W
Wilson
i am very new to c++ and am creating a new program, below are two
seperate parts of the program, made to run seperately, however the
constructor in one works (prints "constructing" on the screen), while
the constructor in the other doesnt. Can you please help me understand
why, i think they are almost identical.
This one works:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class Student
{
public:
Student()
{
cout << "constructing" << endl;
a = 0;
b = 0.0;
}
protected:
int a;
float b;
};
int main(int nNumberofArgs, char* pszArgs[])
{
cout << "Creating a new Student object" << endl;
Student s;
cout << "Creating a second student object" << endl;
Student t;
system("PAUSE");
}
------------------------------------------------------------------------------------------------------------
this one doesnt:
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
class test
{
public:
test()
{
cout << "constructing";
b = 0;
a = 0;
}
protected:
int a;
int b;
};
int main(int nNumberofArgs, char* pszArgs[])
{
cout << "Creating new test object" << endl;
test one;
cout << "creating second test object" << endl;
test two;
system("PAUSE");
}
seperate parts of the program, made to run seperately, however the
constructor in one works (prints "constructing" on the screen), while
the constructor in the other doesnt. Can you please help me understand
why, i think they are almost identical.
This one works:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class Student
{
public:
Student()
{
cout << "constructing" << endl;
a = 0;
b = 0.0;
}
protected:
int a;
float b;
};
int main(int nNumberofArgs, char* pszArgs[])
{
cout << "Creating a new Student object" << endl;
Student s;
cout << "Creating a second student object" << endl;
Student t;
system("PAUSE");
}
------------------------------------------------------------------------------------------------------------
this one doesnt:
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
class test
{
public:
test()
{
cout << "constructing";
b = 0;
a = 0;
}
protected:
int a;
int b;
};
int main(int nNumberofArgs, char* pszArgs[])
{
cout << "Creating new test object" << endl;
test one;
cout << "creating second test object" << endl;
test two;
system("PAUSE");
}