>> ) where do i put the constructor and destructor and why? most of the examples i find are all different.
The constructor is like a 'function' and is generally a public member:
Code:
class thing{
private:
int val;
public:
// ...
thing();
};
//...
thing::thing() {
//put code here
val = 42;
}
It can be used to initialise variables. Say you wanted everything 0, or -1 or something before starting to do anything with the code.
>> my compiler throghs an errror (probably my code), i will comment out my second object louise and maybe you could offer me some advice why.
How do you mean it will comment it out? Do you mean that you have to comment out the second instance to make the code compile?
>> 3) Why do i have to do: ...
Because in making classes you are defining a new type. the computer knows how to read integers, characters, strings, floats etc from the input but you are making your own objects and the computer knows nothing about them.
Code:
class thing{
public: // for the sake of this example.
int one;
char two;
};
If you were cin-ning an instance of thing to what would it assign the input? To the integer one or the character two?
Also, what you posted is only necessary if the variables are not public. The above should work for the class thing above:
Code:
thing i_thing;
cin >> i_thing.one;
Alternatively you can overload the >> operator so you could "cin>> i_thing;" itself. Search the forums if you're interested.