-
April 17th, 2010, 11:18 AM
#1
what is wrong?
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);
}
-
April 17th, 2010, 11:27 AM
#2
Re: what is wrong?
Originally Posted by nlnvcd
what is wrong with this code?
That is the wrong question. There are only a few lines that are not wrong.
Do you have a specific question ?
Kurt
-
April 17th, 2010, 11:38 AM
#3
Re: what is wrong?
thanks for the quick reply kurt
the issue is this "no overloaded function takes 2 arguments" while compiling
-
April 17th, 2010, 11:39 AM
#4
Re: what is wrong?
for starters, class definitions should end with a ;
-
April 17th, 2010, 11:42 AM
#5
Re: what is wrong?
is there anything besides the ";"
-
April 17th, 2010, 11:42 AM
#6
Re: what is wrong?
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' }
};
-
April 17th, 2010, 11:52 AM
#7
Re: what is wrong?
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
-
April 17th, 2010, 12:00 PM
#8
Re: what is wrong?
Originally Posted by nlnvcd
andreas you saved my day, this line does it
fooTest(some_S x, int y) : foo(x, y)
Well...I hope you also understand why the line actually does it...if not, I would suggest reading up on inheritance and constructors...
-
April 17th, 2010, 12:02 PM
#9
Re: what is wrong?
andreas, what's a good book i should read? thanks
-
April 17th, 2010, 12:05 PM
#10
Re: what is wrong?
Code:
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
}
Kurt
-
April 17th, 2010, 10:03 PM
#11
Re: what is wrong?
Originally Posted by nlnvcd
andreas, what's a good book i should read? thanks
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.
Last edited by Andreas Masur; April 17th, 2010 at 10:24 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|