Click to See Complete Forum and Search --> : class visibility


loupus
January 24th, 2010, 11:43 AM
I am new to c++/cli. I looked for several forums but couldnt find a relative answer for my problem. Here, below, two classes in the same namespace. Compiler gives the following error message:
error C2065: 'classA' : undeclared identifier.

When I put the classA before classB it works fine. What is the logic behind this? Is there any way writing classes free from writing sequence?

public ref class classB
{
String^ _b;
public:
void somefunc(){
classA^ clsa = gcnew classA("some string",12);


}
};


public ref class classA
{
private:
Int32 portu;
String^ hostu;

public:
classA(String^ phostu, Int32 pportu)
{
hostu = phostu;
portu = pportu;
}
};

Alex F
January 25th, 2010, 04:29 AM
classA^ clsa = gcnew classA("some string",12);

To compile this line, compiler must have definition of classA. If classA is defined later, this line is not compiled.
To reduce compilation dependencies, it is better to move implementation to .cpp file.