 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
DELORME Frederic Guest
|
Posted: Sun Sep 26, 2004 7:41 pm Post subject: Problem with a static member in a class ? |
|
|
I've the class CNode where there is a static Member m_BaseNode:
The declaration file is : cnode.h
<code> -----------------------------------------------------------
#include <iostream>
#include <cstring>
#ifndef E3DCNODE_H
#define E3DCNODE_H
using namespace std;
namespace E3D {
/**
Noeud d'un arbre
@author DELORME Frederic
*/
class CNode{
public:
CNode();
CNode(string psNodeName);
CNode(string psNodeName, CNode *poParentNode);
~CNode();
void init();
void addChild(CNode *poNodeChild);
void attachTo(CNode *poNodeParent);
void remove(CNode *poNodeChild);
protected:
static CNode *m_BaseNode;
// Nom du noeud
string m_Name;
// Noeud Racine
// Parent de ce noeud
CNode *m_Parent;
// Premier Enfant de ce noeud
CNode *m_Child;
// Enfant suivant de ce noeud
CNode *m_Next;
// Enfant précédent de ce noeud
CNode *m_Prev;
};
};
#endif
----------------------------------------------------------- <code>
And the implemantation file is: cnode.cpp
<code> -----------------------------------------------------------
#include "cnode.h"
namespace E3D {
CNode::CNode(){
this->m_Name = "noname";
this->init();
}
/*!
Création d'un noeud attaché à un parent.
fn E3D::CNode::CNode(string *psNodeName)
param psNodeName : Nom du noeud à créer.
*/
CNode::CNode(string psNodeName)
{
this->m_Name = psNodeName;
this->init();
}
/*!
Création d'un noeud attaché à un parent.
fn E3D::CNode::CNode(CNode *poParentNode)
param poNodeName : Nom du noeud à créer.
param poParentNode : Noeud parent.
*/
CNode::CNode(string psNodeName, CNode *poParentNode)
{
this->m_Name = psNodeName;
poParentNode->addChild(this);
}
/*!
Constructeur par défaut
fn E3D::CNode::CNode().
*/
CNode::~CNode()
{
if(this->m_Child) delete this->m_Child;
if(this->m_Next) delete this->m_Next;
if(this->m_Prev) delete this->m_Prev;
}
void CNode::init(){
if(!this->m_BaseNode){
// oui, alors, on l'initialise
this->m_BaseNode = this;
this->m_Parent = NULL;
}else{
// Sinon on l'ajoute en tant qu'enfant.
this->m_BaseNode->addChild(this);
}
}
/*!
Ajout d'un enfant à cet objet.
fn E3D::CNode::addChild(const CNode *poNodeChild).
param poNodeChild : Noeud enfant à ajouter.
*/
void CNode::addChild(CNode *poNodeChild){
poNodeChild->attachTo(this);
/* // Ce noeud a-t-il des enfants ?
if( this->m_Child == NULL ){
// NON, alors on l'ajoute en tant que premier enfant
this->m_Child = poNodeChild;
poNodeChild->m_Parent = this;
}else{
// OUI, alors, on recherche le dernier enfant
CNode *ptrNode = this->m_Child;
while( ptrNode->m_Next != NULL ){
ptrNode = ptrNode->m_Next;
}
ptrNode->m_Next = poNodeChild;
poNodeChild->m_Prev = ptrNode;
}
*/
}
/*!
Attacher le Noeud courant au noeud parent donné.
fn E3D::CNode::attachTo(CNode *poNodeParent)
param poNodeParent : Parent auquel attacher le noeud.
*/
void CNode::attachTo(CNode *poNodeParent){
if( poNodeParent->m_Child == NULL ){
poNodeParent->m_Child = this;
}else{
CNode *ptrNode = poNodeParent->m_Child;
while( ptrNode->m_Next != NULL ){
ptrNode = ptrNode->m_Next;
}
ptrNode->m_Next = this;
}
}
/*!
Supprimer le noeud donné.
fn E3D::CNode::remove(CNode *poNode).
param poNode : Noeud à supprimer
*/
void CNode::remove(CNode *poNode){
// on récupère les précédents et suivants
if(poNode){
CNode *ptrNext = poNode->m_Next;
CNode *ptrPrev = poNode->m_Prev;
if( &poNode != &this->m_BaseNode ){
// On enlève le noeud de la chaine
if(ptrPrev!=NULL && ptrPrev->m_Next!=NULL) ptrPrev->m_Next = ptrNext;
if(ptrNext!=NULL && ptrNext->m_Prev!=NULL) ptrNext->m_Prev = ptrPrev;
delete poNode;
}else{
delete this;
}
}
}
};
----------------------------------------------------------- <code>
The problem is that i've the next error while compiling:
<log> ------------------------------------------------------------
*/home/fred/Projets/cpp/testsdl/src/cnode.cpp:61: undefined reference to
`E3D::CNode::m_BaseNode'
*cnode.o(.text+0x50b):/home/fred/Projets/cpp/testsdl/src/cnode.cpp:63:
undefined reference to `E3D::CNode::m_BaseNode'
*cnode.o(.text+0x523):/home/fred/Projets/cpp/testsdl/src/cnode.cpp:67:
undefined reference to `E3D::CNode::m_BaseNode'
*/home/fred/Projets/cpp/testsdl/src/cnode.cpp:122: undefined reference to
`E3D::CNode::m_BaseNode'
------------------------------------------------------------ <log>
anybody Any idea ? )
thanks for any help !
F.Delorme.
|
|
| Back to top |
|
 |
David Hilsee Guest
|
Posted: Sun Sep 26, 2004 7:48 pm Post subject: Re: Problem with a static member in a class ? |
|
|
"DELORME Frederic" <delorme.frederic (AT) free (DOT) fr> wrote
| Quote: | I've the class CNode where there is a static Member m_BaseNode:
The declaration file is : cnode.h
code> -----------------------------------------------------------
#include <iostream
#include
#ifndef E3DCNODE_H
#define E3DCNODE_H
using namespace std;
namespace E3D {
/**
Noeud d'un arbre
@author DELORME Frederic
*/
class CNode{
public:
CNode();
CNode(string psNodeName);
CNode(string psNodeName, CNode *poParentNode);
~CNode();
void init();
void addChild(CNode *poNodeChild);
void attachTo(CNode *poNodeParent);
void remove(CNode *poNodeChild);
protected:
static CNode *m_BaseNode;
// Nom du noeud
string m_Name;
// Noeud Racine
// Parent de ce noeud
CNode *m_Parent;
// Premier Enfant de ce noeud
CNode *m_Child;
// Enfant suivant de ce noeud
CNode *m_Next;
// Enfant précédent de ce noeud
CNode *m_Prev;
};
snip |
| Quote: | The problem is that i've the next error while compiling:
log> ------------------------------------------------------------
*/home/fred/Projets/cpp/testsdl/src/cnode.cpp:61: undefined reference to
`E3D::CNode::m_BaseNode'
*cnode.o(.text+0x50b):/home/fred/Projets/cpp/testsdl/src/cnode.cpp:63:
undefined reference to `E3D::CNode::m_BaseNode'
*cnode.o(.text+0x523):/home/fred/Projets/cpp/testsdl/src/cnode.cpp:67:
undefined reference to `E3D::CNode::m_BaseNode'
*/home/fred/Projets/cpp/testsdl/src/cnode.cpp:122: undefined reference to
`E3D::CNode::m_BaseNode'
------------------------------------------------------------
anybody Any idea ? )
thanks for any help !
|
Where's the definition of E3D::CNode::m_BaseNode? See the FAQ
(http://www.parashift.com/c++-faq-lite/) Section 10 (Constructors) question
10 (Why are classes with static data members getting linker errors?).
--
David Hilsee
|
|
| Back to top |
|
 |
DELORME Frederic Guest
|
Posted: Sun Sep 26, 2004 8:01 pm Post subject: Re: Problem with a static member in a class ? |
|
|
David Hilsee wrote:
| Quote: |
Where's the definition of E3D::CNode::m_BaseNode? See the FAQ
(http://www.parashift.com/c++-faq-lite/) Section 10 (Constructors)
question 10 (Why are classes with static data members getting linker
errors?).
|
thanks a lot, i'll run there !
--
<hr width="100%" size="2" noshadow/>
F.Delorme<delorme.frederic (AT) free (DOT) fr>
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|