C++ string "Undefined symbols" error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: C++ string "Undefined symbols" error

  1. #1
    Join Date
    Feb 2010
    Posts
    3

    C++ string "Undefined symbols" error

    Hello all - always hate to make my first post but after more than an hour of looking I can't figure out what I have done wrong...

    I'm writing a simple program to store a tree of strings, and am getting the following error after compiling with g++.

    Code:
    Undefined symbols:
      "Ontology::InsertTerm(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, ItemType*)", referenced from:
          Ontology::InsertTerm(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)in ccDEky9Q.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    Here is my Ontology.cpp file:
    Code:
     // Johan Henkens and Kevin Wang for CS24 Lab06 Winter 2010 UCSB
    
    #include "Ontology.h"
    
    Ontology::Ontology(ItemType* type){ 
      head.push_back(type);
    }
    //Observers
    bool Ontology::IsEmptyOnt(){
      return head.size()==0;
    }
    
    // "" signifies no parent
    bool Ontology::InsertTerm(string parent, string newNode){
      if(parent.compare("")==0){
    	ItemType* tempRef = new ItemType();
        tempRef->Initialize(newNode, NULL);
        head.push_back(tempRef);
        return true;
      } 
      for(int i = 0; i < head.size();i++){
        if(head[i]->GetData()==parent){
          for(int o = 0; o<head[i]->getChildrenSize();o++){
    	if(head[i]->getChild(o)->GetData().compare(newNode)==0) return true;
          }
          ItemType* temp = new ItemType();
          temp->Initialize(newNode,head[i]);
          head[i]->pushToChildren(temp);
          return true;
        }
      }
      for(int i = 0; i < head.size();i++){
        if(InsertTerm(parent, newNode, head[i])) return true;
        }
        return false;
    }
    bool InsertTerm(string parent, string newNode, ItemType* root){
      if(root->GetData()==parent){
        for(int i = 0; i<root->getChildrenSize();i++){
          if(root->getChild(i)->GetData().compare(newNode)) return true;
        }
        ItemType* temp = new ItemType();
        temp->Initialize(newNode,root);
        root->pushToChildren(temp);
        return true;
      }
      for(int i = 0; i < root->getChildrenSize();i++){
        if(InsertTerm(parent, newNode, root->getChild(i))) return true;
      }
        return false;
    }
    Inside an included header in Ontology.h is
    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    using namespace std;
    so I doubt it is that I haven't included the right libraries.

    I am completely lost as to where I am to go from here. Any advice would be wonderful

  2. #2
    Join Date
    Feb 2010
    Posts
    3

    Re: C++ string "Undefined symbols" error

    Yuck! Wrong subforum (I think?). My apologies

  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,565

    Re: C++ string "Undefined symbols" error

    In your cpp file you have:

    Code:
    bool InsertTerm(string parent, string newNode, ItemType* root){
    You just forgot the class name

    Code:
    bool Ontology::InsertTerm(string parent, string newNode, ItemType* root){

  4. #4
    Join Date
    Feb 2010
    Posts
    3

    Re: C++ string "Undefined symbols" error

    Quote Originally Posted by Philip Nicoletti View Post
    In your cpp file you have:

    Code:
    bool InsertTerm(string parent, string newNode, ItemType* root){
    You just forgot the class name

    Code:
    bool Ontology::InsertTerm(string parent, string newNode, ItemType* root){
    That was it! Thank you very much.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center