#include <iostream>
#include <fstream>
using namespace std;
class tester
{
public:
int field1;
int field2;
int field3;
int field4;
tester (int var1, int var2, int var3, int var4);
//tester (void);
}
tester::tester (int var1=10, int var2=11, int var3=12, int var4=13): field1(var1), field2(var2), field3(var3), field4(var4)
{
cout << "Initialized constructor called." << endl;
}
/*
tester::tester(void)
{
cout << "Default constructor called." << endl;
}
*/
int main () {
tester ex1;
cout << "Field 1 = " << ex1.field1 << endl
<< "Field 2 = " << ex1.field2 << endl
<< "Field 3 = " << ex1.field3 << endl
<< "Field 4 = " << ex1.field4 << endl;
tester ex2 (1,2,3,4);
cout << "Field 1 = " << ex2.field1 << endl
<< "Field 2 = " << ex2.field2 << endl
<< "Field 3 = " << ex2.field3 << endl
<< "Field 4 = " << ex2.field4 << endl;
return 0;
}
1>Compiling...
1>main.cpp
1>c:\documents and settings\luke jordan\my documents\visual studio 2008\projects\wg prot 1\wg prot 1\main.cpp(17) : error C2533: 'tester::{ctor}' : constructors not allowed a return type
1>c:\documents and settings\luke jordan\my documents\visual studio 2008\projects\wg prot 1\wg prot 1\main.cpp(29) : error C2264: 'tester::tester' : error in function definition or declaration; function not called
1>c:\documents and settings\luke jordan\my documents\visual studio 2008\projects\wg prot 1\wg prot 1\main.cpp(34) : error C2264: 'tester::tester' : error in function definition or declaration; function not called
The warning messages indicate my constructor has a return type, but it clearly doesn't. I tried changing to void and it returns more errors. Can anyone help me spot the problem?
Thanks,
Luke


Sign In
Create Account


Back to top









