|
-
November 22nd, 2008, 03:16 AM
#1
inheritance, copy costructors and assignment operators issue
Hello everybody, since last year i've been developing an SDL-based library for videogames,
but lately i'm stuck on a problem that concerns (i think) inheritance and copy costructors/assignment operators.
I've done lot of searching over internet for a solution but still i don't get it.
Here it is a sum of the code:
Code:
// base class (concrete)
class GFX
{
protected:
// some fields
// ...
public:
// base constructor
GFX()
{
// fields inizializations
//...
}
// default constructor
GFX( const char *file,
const SDL_Color Transparent = None,
const u16 InitNoFrames = 1 )
{
GFX();
// more fields inizialization
// ...
}
// methods
}
// 1st level derived class (abstract)
class ScreenObject : public GFX
{
protected:
// some fields and methods
public:
ScreenObject()
{
// fields inizializations
//...
}
// methods (some virtuals, some not)
virtual void Draw() = 0; // abstract method
}
// 2nd level derived class (concrete)
class Sprite : public ScreenObject
{
public:
// some fields
// Sprite constructor
Sprite()
{
// fields inizializations
//...
}
//! Alternative sprite constructor
Sprite( const GFX& InitGFX )
{
Sprite();
*this = InitGFX; // ???
// GFX::operator=( InitGFX );
}
// methods (some virtuals, some not)
}
As you can see i've declared no copy costructor or assignment operators,
meaning i would like to use the default ones that performs field-by-field copy.
The problem arise in the "Alternative sprite constructor".
Here i would like to do a field-by-field copy between an object of the
base class GFX and the derived class Sprite.
I don't know why, but it seems that operator= does not work as expected, and i get
lot of invocations of the Sprite constructor that don't returns.
Thanks in advance for answering!
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
|