[SOLVED] Copy Constructors (C++)

Started by
19 comments, last by AsOne 18 years ago
Quote:Original post by AsOne
"note: candidates are: CEntity::CEntity(const CEntity&)"                        CEntity::CEntity(const irr::core::stringw&, irr::scene::IAnimatedMesh*, irr::IrrlichtDevice*)



Does that second constructor have its second and third parameters declared with default values?

Stephen M. Webb
Professional Free Software Developer

Advertisement
Quote:Original post by Bregma
Quote:Original post by AsOne
"note: candidates are: CEntity::CEntity(const CEntity&)"                        CEntity::CEntity(const irr::core::stringw&, irr::scene::IAnimatedMesh*, irr::IrrlichtDevice*)



Does that second constructor have its second and third parameters declared with default values?

They do not, I just tried adding in default values though and the problem still persists :(
OK this is wierd now ... I have made this a non-derived class, and have also removed the normal constructor, this happens ...
class CEntity // : public irr::scene::ISceneNode{ <------ "note: candidates are: CEntity::CEntity()"public:    /*    CEntity(        const irr::core::stringw &name,        irr::scene::IAnimatedMesh *mesh,        irr::IrrlichtDevice *device    );    */    virtual ~CEntity();               virtual CEntity *clone() const    {        return new CEntity(*this); <------ "note: CEntity::CEntity(const CEntity&)"    }    ...

I'm beginning to think I've done something really small, stupid, and obvious somewhere, I really want to delete every line of code in the entire project and just start over!
Quote:Original post by AsOne
OK this is wierd now ... I have made this a non-derived class, and have also removed the normal constructor, this happens ...


Hmm, I seem to recall seeing something like that when I was missing a semicolon or had an unmatched parenthesis somewheres lexically preceeding the error.

Stephen M. Webb
Professional Free Software Developer

Can you paste the full, actual code? It's hard to debug "..."
This is entity.h, for anyone who uses Irrlicht, it's basically just like IAnimatedMeshSceneNode. I'm not sure if the implementation of this class would help in solving the problem.
#ifndef _ENTITY_H_#define _ENTITY_H_#include <irrlicht.h>class CEntity // : public irr::scene::ISceneNode{public:    /*    CEntity(        const irr::core::stringw &name,        irr::scene::IAnimatedMesh *mesh,        irr::IrrlichtDevice *device    );    */    virtual ~CEntity();               virtual CEntity *clone() const    {        return new CEntity(*this);    }         // functions    virtual int getCurrentFrame();    virtual void setCurrentFrame(int frame);    virtual bool setFrameLoop(int begin, int end);    virtual void OnPreRender();    virtual void render();    virtual void OnPostRender(unsigned int time);    virtual irr::video::SMaterial &getMaterial(int i);    virtual irr::scene::ISceneNode *getJointNode(const char *jointName);    virtual bool removeChild(irr::scene::ISceneNode *child);    virtual irr::core::aabbox3d<float> getCorrectedBoundingBox() const;        // inline    virtual inline void setAnimationSpeed(int framesPerSecond)    {        FramesPerSecond = framesPerSecond;    }    virtual inline void setLoopMode(bool looping)    {        Looping = looping;    }    inline unsigned int getMaterialCount() const    {        return Materials.size();    }    virtual inline const irr::core::aabbox3d<float> &getBoundingBox() const    {        return Mesh->getBoundingBox();    }protected:    inline unsigned int getTimeSinceLastFrame()    {        return TimeSinceLastFrame;    }private:    irr::ITimer *Timer;    irr::scene::IAnimatedMesh *Mesh;    unsigned int LastTime;    unsigned int TimeSinceLastFrame;    unsigned int BeginFrameTime;    int StartFrame;    int EndFrame;    int FramesPerSecond;    bool Looping;    irr::core::array<irr::video::SMaterial> Materials;    irr::core::array<irr::scene::IDummyTransformationSceneNode*> JointChildSceneNodes;    };#endif

The only errors in this file are the ones pointed out in my last post.
try:

  CEntity& ref = *this;  return new CEntity(ref);


to see what happens...

or

  CEntity* p = new CEntity();  (*p) = (*this);  return p;


Just blindly guessing here.
[size="2"]I like the Walrus best.
OK when I do this ...
CEntity &ref = *this;

It gives me the error ...
 error: invalid initialization of reference of type 'CEntity&' from expression of type 'const CEntity' 

However, when I put const infront, it is fine with it, yet I still get the same error on the line as I always did...
return new CEntity(ref);
Wait, yeah the const thing is just becasue I declared the function as const.

Now trying the other way ...
We can clearly see that gcc does crack. This is actually what the error says ...
virtual CEntity *clone() const{    CEntity* p = new CEntity(); <--- "note: candidates are: CEntity::CEntity()"    (*p) = (*this);    return p;}

I find that hard to beleive as right above that function I declared a constructor ...
CEntity::CEntity() { }

I'm using Eclipse so I first thought maybe it's parsing gcc's output wrong, but it isn't. :(

It seems that all the other classes I derived from CEntity have the same strange error as I mentioned before, e.g.
class CItem : public CEntity
{ <--- note: candidates are: CItem::CItem(const CItem&)
... AHHHHHHHHH
Uh.. "virtual inline" ? How does that work? heh
Quote:Original post by AsOne
I'm using Eclipse so I first thought maybe it's parsing gcc's output wrong, but it isn't.


What's the full GCC output in the console view? I've found that with some errors that have extra information on new lines (ie. the 'note:' lines) it will display the extra info as the error and not the error itself. The full output might have that extra peice of info needed to complete the puzzle.

Quote:Original post by RDragon1
Uh.. "virtual inline" ? How does that work? heh


Actually the 'inline' is redundant, any functions that include the function body inside the class definition are automagically inlined. The inline part works because where ever the compiler *can* inline the function it will (eg. using the Entity class directly), but it will also generate an out-of-line version for when working with derived classes.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement