assigning the address of a variable in c++
hi all,
im very new to c++ and programming, googled this but couldnt find an answer
if i want a instance of a variable, i can do this
int a = 10;
int & b (a);
so now the address of both a and b are the same, if i change one the other contains the same value as they are both the same address.
now i have a class like so
class testClass {
public:
int testInt;
string testString;
testClass() : testInt(0), testString("") {}
testClass(int& i, string& s) {
testInt = i;
testString = s;
}
};
what i want to do is create 2 instances of this class first and second like so
testClass first;
testClass second;
and here is where i dont know if i can do what i want.
i want to assign first.testString to a value such as "blah"
now i want the address of second.testString to be the same as first.tesString so that they are the same Adress and chaning one changes both. but i dont want the whole class to have the same address... i.e.
i can do
testClass first;
testClass &second(first)
but i dont want that, i want only one of the member variables to have the same addresses
is this possible or is there a better way to do this??
thanks
mono
__________________