navi Messages: 107 Registered: February 2012 Location: Sydney, Australia
Experienced Member
Quote:
H1::t1 <<= "2 OK"; // error: 'H1' : is not a class or namespace name
in C++ this is not how one access non static class members. its like this
H1 a;
a.t1 = "something";
Quote:
I am on Win7 64bit running U++ 5556
On Win7 32bit and U++ 5584 the problems are the same.
Same with U++ 5592
I may have overlooked something so here it is with the last changes.
again, these error has nothing to do with U++. they are all valid compiler errors for your wrong code.
Quote:
I made the 2 changes and now get this:
c:\myapps\test2\H2.h(9) : error C2653: 'H1' : is not a class or namespace name
c:\myapps\test2\H2.h(13) : error C3861: 'Set_t1': identifier not found
H1::t1 <<= "2 OK"; // error: 'H1' : is not a class or namespace name
all the errors are scope related. if you right your class in plain c++ and use t1 as string variable and use cout to print out. you will still get the same errors. because they are from C++ compiler and has nothing to do with U++ or your Windows version.
class H1{
public:
int t1; // t1 is in the class h1's scope
// this function also in h1's scope
void AddFun1(int a, int b)
{
t1=a+b; // valid t1 access.
}
};
// regardless weather the below function is in
// h1.h or h2.h or main.cpp or anyother file in
// that matter is still in global scope
void AddFun2(int a, int b)
{
// this is function scope
// t1 is not visible here
// no object of H1 class also is non existent
// since you did not create any.
// but you can do this:
H1 c;
c.AddFun1(1,1);
cout<<c.t1;
c.t1=a+b;
cout<<c.t1;
// all t1 of c object of H1 class are valid but c gets
// destroyed as soon as function scope is finish.
}