Click to See Complete Forum and Search --> : Error code C2039


sivaprakash.shanmugam
May 23rd, 2006, 11:24 PM
Hi,

I am trying to access some methods from user defined class it doesnt allow me to do, it says SetValue() is not a member of Class1

Here is the code

Class1 *obj = new Class1 () ;
obj->SetValue ();

Do I need to set any properties specifically to access this method.

ThermoSight
May 23rd, 2006, 11:46 PM
Just a quickie comment .....

.... is SetValue defined as "void Class1::SetValue(void) {}// end function 'setValue' ",

and is SetValue declared in the class definition?

If you left the class scope operator ("Class1::") off, or didn't declare the function in the class definition (i.e. private: void SetValue(void); )then the compiler's right ... it really isn't a member of the class.

I would think that if both of those are a 'GO', then I would not expect the compiler to report that SetValue is not a member of Class1.

Those'd be the first two things I'd check.

Best wishes.

bill

humptydumpty
May 23rd, 2006, 11:59 PM
can u show your code how u defined a Class.This is not The nought code to Find Out Why u r getting error.
Here is a Simple Example for you

#include <iostream>
using namespace std;

class Fred {
const int size;
public:
Fred(int sz);
void print();
};

Fred::Fred(int sz) : size(sz) {}
void Fred::print()
{
cout << size << endl;
}

int main()
{
Fred a(1), b(2), c(3);
a.print(), b.print(), c.print();
return 0;
}

sivaprakash.shanmugam
May 24th, 2006, 01:06 AM
This is my Class still i am not able to access this method.

class Class1
{

public:
void SetValue();

};

Class1::SetValue ()
{
MessageBox::Show ("Hi");
}

humptydumpty
May 24th, 2006, 01:21 AM
just try to Find out yourself what's wrong u r doing here :) . here is your Working code

class Class1
{
public:
void SetValue();

};

void Class1::SetValue ()
{
cout<<"Hello";
}
int main()
{
Class1 *obj = new Class1();
obj->SetValue();
delete obj;
return 0;
}


thanx

sivaprakash.shanmugam
May 24th, 2006, 01:38 AM
No still same issue..

Actually i am writting it as a class library and accessing that method. Still i can able to access all the member variables; but not methods.

Please help me out.