what is wrong with this code?
class foo
{
public:
foo();
foo(some_S x, int y);
~foo();
}
class fooTest : public foo
{
}
test()
{
some_S x = something;
int y = 0;
fooTest fTest(x, y);
}
Printable View
what is wrong with this code?
class foo
{
public:
foo();
foo(some_S x, int y);
~foo();
}
class fooTest : public foo
{
}
test()
{
some_S x = something;
int y = 0;
fooTest fTest(x, y);
}
thanks for the quick reply kurt
the issue is this "no overloaded function takes 2 arguments" while compiling
for starters, class definitions should end with a ;
Code:class aClass
{
};
is there anything besides the ";"
The compiler does not find a suitable constructor to create the 'fTest' object. 'fooTest' only has the default constructor (taking no arguments) available. You need to explicitly provide a suitable constructor....
Aside from this...your destructor should be declared virtual in case you want to derive from the class. Finally, you are missing a semi-colon at the end of the class declaration.
Code:class foo
{
public:
foo();
foo(some_S x, int y);
virtual ~foo();
};
class fooTest : public foo
{
fooTest(some_S x, int y) : foo(x, y) { // do some other initialization for 'fooTest' }
};
andreas you saved my day, this line does it
fooTest(some_S x, int y) : foo(x, y)
everyone thanks for all of your comment
andreas, what's a good book i should read? thanks
KurtCode:class foo
{
public:
foo(); // not implemented
foo(some_S x, int y); // some_S unknown
~foo(); // not implemented should propably be virtual
} // missing semicolon
class fooTest : public foo
{
} // missing semicolon
test() // no return type
{
some_S x = something; // something unknown
int y = 0;
fooTest fTest(x, y); // fooTest has no constructor that takes a some_s and an int
// foo fTest(x,y); would be correct
}
That is certainly a pretty broad question. I do not know your background and thus it is kind of hard to provide specific advice. In case you already know some basics (form a different language for example), I usually recommend 'Accelerated C++'.
Other than that, Bruce Eckel's 'Thinking in C++' is quite good and is actually available for free online.