Trouble with non-default constructors
From: Peter Venis (petervenis_at_zonnet.nl)
Date: 07/10/04
- Next message: Francis Glassborow: "Re: Trouble with non-default constructors"
- Previous message: Robert W Hand: "Re: Default constructors, passing argument"
- Next in thread: Francis Glassborow: "Re: Trouble with non-default constructors"
- Reply: Francis Glassborow: "Re: Trouble with non-default constructors"
- Reply: Chad J McQuinn: "Re: Trouble with non-default constructors"
- Reply: SaltPeter: "Re: Trouble with non-default constructors"
- Reply: jeffc: "Re: Trouble with non-default constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 10 Jul 2004 16:14:26 +0200
Hi,
I have a class that needs a non-default constructor, the class is supposed
to look like this:
class MyClass
{
protected:
int Value;
public:
MyClass(int V);
~MyClass();
void GetValue(){return Value);
};
But if I try to compile my compilers complains there's no default
constructor, but I don't want a default constructor (???)
To try and hack myself around this problem I do this:
class MyClass
{
protected:
int Value;
public:
MyClass(){} // Why can't I leave out this obsolete line of code?
MyClass(int V);
~MyClass();
void GetValue(){return Value);
};
Is there a better way to solve this?
And there's another problem, when I create a class that's derived from
MyClass, something like class MyChildClass : public MyClass, then I cannot
use the non-default constructor for that class becuase the compiler says it
does not exist (??). What am I doing wrong?
Peter
- Next message: Francis Glassborow: "Re: Trouble with non-default constructors"
- Previous message: Robert W Hand: "Re: Default constructors, passing argument"
- Next in thread: Francis Glassborow: "Re: Trouble with non-default constructors"
- Reply: Francis Glassborow: "Re: Trouble with non-default constructors"
- Reply: Chad J McQuinn: "Re: Trouble with non-default constructors"
- Reply: SaltPeter: "Re: Trouble with non-default constructors"
- Reply: jeffc: "Re: Trouble with non-default constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|