I was writing a simple class to test my understanding of class and the first class program had a number -int num private- that was modified by the user by void definenum(num) and retrieved with int getnum(). It functioned as I expected-i would define it as 4 and it would retrieve 4. However when i tried to add a constructor to initialize the program it got nutty. It compiled fine with this code:
header:
class numgetter{
private:
int num;
public:
numgetter()
{num=0;}
void definenum(int num)
{}
int getnum()
{
return num;
}
};
main:
#include<iostream>
#include"class_header.h"
using namespace std;
int main()
{
class numgetter test;
int in_num;
cout<<"Input the number";
cin>>in_num;
test.definenum(in_num);
cout<<test.getnum();
system("pause");
}
I would input 4 and it would retrieve 0.
Why doesnt it have the constructor numgetter() execute when I make the new instance of it, rather all the time-or so it seems?