Your problem stems from the fact that you have
declared your variables inside the constructor. These are not member variables, but local variables that will go out of scope when the constructor has finished executing.
You need to any member variables, as you have done your methods. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
class myClass
{
int *myInt; //the member variables are declared inside the class and not
char *myChar; //inside a method of that class
//constructor
myClass()
{
myInt = new int(); //member methods are initialised inside the constructor
myChar = new char();
}
//and so on
};
|
Notice in the above example I have referred to the
classes members directly by name, with no use of the this pointer. A class has full access to all of it's
own members and methods (
public, private and protected. Atleast I think so :) ).
But another class cannot invoke a classes
private members and methods from outside of the class. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class myClass
{
public:
int notsosecret;
private:
int secret;
};
int main()
{
myClass mclass;
mclass.secret = 10; //this will cause an error
mclass.notsosecret = 10; //no problem
}
|
I can't tell you too much about the this pointer as I've never really used it but I'm sure a more experienced user can help you out with that.
You probably have already seen the tutorials on this website on classes, but in case you haven't here are some links:
Classes (part 1):
http://www.cplusplus.com/doc/tutorial/classes/
Classes (part 2):
http://www.cplusplus.com/doc/tutorial/classes2/
Classes (part 2) has a section on the this
pointer.