c++ recursive class
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: c++ recursive class

  1. #1
    Join Date
    Aug 2009
    Posts
    84

    c++ recursive class

    Hello everyone!!!

    I'd need a little hint on this little question:

    I have a xml file I want to navigate and I have a library to process
    it. But I want also to manage that file as an object to make clear and
    efficient code.
    So I coded two class which one is like recursive as like as in this
    example:

    class B : public xmlnode
    {
    public:
    B(xmlnode* member);

    LPCSTR getattribute(....);
    void setattribute(....);

    xmlnode* Node(LPCSTR nodename, LPCSTR attributenodename, LPCSTR
    attributetosearch);

    };

    class A : public xmldocument
    {
    public:
    A(LPCSTR xmlfilename);

    xmlnode* Node(LPCSTR nodename, LPCSTR attributenodename,
    LPCSTR attributetosearch);

    };

    So I can do this:

    A* xmlobject = new A(filenamexmlblahblah);
    xmlobject->Node(....,....,...)->Node(...,...,...)->GetAttribute(...);

    where next nodes are nodes inside a parent node...but I get this link
    error:

    error LNK2019: unresolved external symbol "public: class B *
    __thiscall B::Node(....)" ....

    what I could have missed?...
    Even I'm just using a function that returns class node itself....

    Thanks to everyone!
    Ciao
    Luigi

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,266

    Re: c++ recursive class

    It looks like you just forgot to implement the B::Node member function.

    By the way, please post your code in [code][/code] bbcode tags.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Aug 2009
    Posts
    84

    Re: c++ recursive class

    Yes I just forgot to say I implemented in the CPP file:

    Code:
    xmlnode* xmlnode::Node(LPCSTR nodename,  LPCSTR attributenodename,
    LPCSTR
    attributetosearch)
    {
    ....
    
    }
    but still I get that error

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,266

    Re: c++ recursive class

    That is the definition of xmlnode::Node, not B::Node.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Aug 2009
    Posts
    84

    Re: c++ recursive class

    Ah sorry.... I typed wrong... I wanted to say in fact

    Code:
    class B : public xmlnode
    {
    public:
    B(xmlnode* member);
    
    LPCSTR getattribute(....);
    void setattribute(....);
    
    B* Node(LPCSTR nodename, LPCSTR attributenodename, LPCSTR
    attributetosearch);
    
    };
    
    class A : public xmldocument
    {
    public:
    A(LPCSTR xmlfilename);
    
    B* Node(LPCSTR nodename, LPCSTR attributenodename,
    LPCSTR attributetosearch);
    
    };
    
    B* B::Node(LPCSTR nodename,  LPCSTR attributenodename,
    LPCSTR
    attributetosearch)
    {
    ....
    
    }
    and I get that error....

  6. #6
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,266

    Re: c++ recursive class

    Weird. I suggest that you reduce your program to the smallest and simplest program that demonstrates that error, then post the resultant program.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  7. #7
    Join Date
    Aug 2009
    Posts
    84

    Re: c++ recursive class

    Here the attachment for smallest and simplest demo application which at Button1 click should read the xml file and show in the edit box its value and instead I get this error:

    1>prova_tinyxmlDlg.obj : error LNK2019: unresolved external symbol "public: char const * __thiscall documentTinyNode::GetAttribute(char const *)" (?GetAttribute@documentTinyNode@@QAEPBDPBD@Z) referenced in function "public: void __thiscall Cprova_tinyxmlDlg::OnBnClickedButton1(void)" (?OnBnClickedButton1@Cprova_tinyxmlDlg@@QAEXXZ)
    1>prova_tinyxmlDlg.obj : error LNK2019: unresolved external symbol "public: class documentTinyNode * __thiscall documentTinyNode::Node(char const *,char const *,char const *)" (?Node@documentTinyNode@@QAEPAV1@PBD00@Z) referenced in function "public: void __thiscall Cprova_tinyxmlDlg::OnBnClickedButton1(void)" (?OnBnClickedButton1@Cprova_tinyxmlDlg@@QAEXXZ)
    1>prova_tinyxmlDlg.obj : error LNK2019: unresolved external symbol "public: class documentTinyNode * __thiscall documentTinyXML::Node(char const *,char const *,char const *)" (?Node@documentTinyXML@@QAEPAVdocumentTinyNode@@PBD00@Z) referenced in function "public: void __thiscall Cprova_tinyxmlDlg::OnBnClickedButton1(void)" (?OnBnClickedButton1@Cprova_tinyxmlDlg@@QAEXXZ)
    1>prova_tinyxmlDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall documentTinyXML::documentTinyXML(char const *)" (??0documentTinyXML@@QAE@PBD@Z) referenced in function "public: void __thiscall Cprova_tinyxmlDlg::OnBnClickedButton1(void)" (?OnBnClickedButton1@Cprova_tinyxmlDlg@@QAEXXZ)
    1>I:\projects\project_tests\prova_tinyxml\Debug\prova_tinyxml.exe : fatal error LNK1120: 4 unresolved externals

    Any suggest?...
    Attached Files Attached Files

  8. #8
    Join Date
    Apr 2009
    Posts
    21

    Re: c++ recursive class

    Hi,
    This error: "error LNK2019: unresolved external symbol .. " said
    Linker could not find and definition of "documentTinyNode::GetAttribute" (for example)
    Take note in your documentTinyNode class has only declaration of GetAttribute method.

    and u must implement documentTinyNode::GetAttribute to resolve LNK2019 error

  9. #9
    Join Date
    Aug 2009
    Posts
    84

    Re: c++ recursive class

    Sorry I forgot something to attach in the package source... here the correct attachment test example... as you can see there are in the .cpp implementations of GetAttribute, SetAttribute and B:Node... but I still get that error...

    Thanks
    Ciao
    Luigi
    Attached Files Attached Files

  10. #10
    Join Date
    Apr 2009
    Posts
    21

    Re: c++ recursive class

    Quote Originally Posted by npuleio View Post
    Sorry I forgot something to attach in the package source... here the correct attachment test example... as you can see there are in the .cpp implementations of GetAttribute, SetAttribute and B:Node... but I still get that error...

    Thanks
    Ciao
    Luigi

    Your source code (prova_tinyxmlDlg.cpp) still missing implement documentTinyXML::Node(..)
    Please complete implementation and rebuild your project

  11. #11
    Join Date
    Aug 2009
    Posts
    84

    Re: c++ recursive class

    Ehm... isn't implemented in prova_tinyxmlDlg.cpp almost at begin of the file?....

  12. #12
    Join Date
    Aug 2009
    Posts
    84

    Re: c++ recursive class

    Ah sorry.... now I understand... I shall implement also documentTinyXML::Node(..) when actually I implemented only documentTinyNode()...

    I guess that member documentTinyXML::Node() should be implemented as like:

    documentTinyNode* documentTinyXML::Node(LPCSTR nodename, ........ , ....... )
    {
    documentTinyNode::Node(nodename, ..... , ..... );
    }

    as an override of the documentTinyNode's function to get a node object... but those two classes aren't of same parent but just different objects... how it should be implemented then?...

    Thanks
    Ciao
    Luigi

  13. #13
    Join Date
    Apr 2009
    Posts
    21

    Re: c++ recursive class

    Hi,
    First of all, You should take a look at http://w3schools.com/xml/xml_tree.asp
    "XML documents must contain a root element. This element is "the parent" of all other elements..."

    As Xml document tree
    the documentTinyXML class should be
    class documentTinyXML
    {
    .....
    public:
    List<documentTinyNode> GetChildNodes(); // Return a collection of xmlNode
    };

    There is a good book Programming - Object-Oriented Analysis and Design - C++ to read
    and your choose are yours

    Merry Christmas !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center