Class help (understanding)
Ok, im working on classes (since i abandoned my MUD codebase until i can actualy use C++) but im a tiny bit confused on the constructor and destructor... i dont know how to add arguments yet so im not worried about that on the constructor, but does the program automatically call those functions? or do i have to put something to stop them myself? here is an example i just made using them :D
Code:
#include <iostream>
using namespace std;
class Montez {
public:
Montez();
~Montez();
void talk();
int number;
};
Montez::Montez() {
}
Montez::~Montez() {
}
void talk(Montez &M) {
cout<<"TADA! it works! "<<endl;
cout<<"And, your number was "<<M.number<<". "<<endl;
}
int main() {
Montez Monte;
cout<<"Enter a number: ";
cin>>Monte.number;
cin.get();
talk(Monte);
}
:D i also did some practice on using functions to call structures and it apparently works for classes too... so is there a way i have to call the destructor or constructor? or is there anywere in that (small) code that i messed up on? thanks for the help :) C++ is starting to get easier...