Thread: Need help with template node assignment.

  1. #61
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Come on...
    This will not event compile. Furthermore, it's wrong, wrong, wrong.
    When will you learn to test your code? Go test your code before you post any further. Go compile it!
    Heck, go learn the using a debugger as you've been told. Do it. You have absolutely no excuse for not doing it now.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #62
    Registered User
    Join Date
    Feb 2015
    Posts
    225
    I have difficultly understanding how to isolate the code enough to compile and test it but...I think I've made a breakthrough. There's still some compiling issues, (from the node itself now) and I'm having trouble understanding it, but I think I'm almost done. These are the four files from before, but the bs_treet files have been altered significantly. The test is, of course, the same.

    ~~~Node~~~

    Code:
    #ifndef BST_NODET_H
    #define BST_NODET_H
    #include <string>
    #include <climits>
    
    template <typename T>
    class BSTNodeT {
    public:
      BSTNodeT();
      BSTNodeT(T contents);
      ~BSTNodeT();
      void SetContents(T contents);
      void SetLeft(BSTNodeT node);
      void SetRight(BSTNodeT node);
      void IncrementCount();
      void DecrementCount();
      T GetContents() const;
      BSTNodeT* GetLeft() const;
      BSTNodeT* GetRight() const;
      int GetCount();
    private:
      T contents_;
      BSTNodeT<T>* left_;
      BSTNodeT<T>* right_;
      int count_;
    };
    
    #endif /* BST_NODET_H */
    Code:
    #include "bst_nodet.h"
    #include <iostream>
    #include <string>
    #include <sstream>
    using std::string;
    using std::stringstream;
    
    BSTNodeT::BSTNodeT() {
      left_ = NULL;
      right_ = NULL;
      contents_ = T();
      count_ = 0;
    }
    
    BSTNodeT::BSTNodeT(T contents) {
      left_ = NULL;
      right_ = NULL;
      contents_ = contents;
      count_ = 0;
    }
    
    BSTNodeT::~BSTNodeT() {
      left_ = NULL;
      right_ = NULL;
    }
    
    void BSTNodeT::SetContents(T contents) {
      contents_ = contents;
    }
    
    void BSTNodeT::SetLeft(BSTNodeT node) {
      left_ = node;
    }
    
    void BSTNodeT::SetRight(BSTNodeT node) {
      right_ = node;
    }
    
    void BSTNodeT::IncrementCount() {
      count_++;
    }
    
    void BSTNodeT::DecrementCount() {
      count_--;
    }
    
    T BSTNodeT::GetContents() const {
      return contents_;
    }
    
    BSTNodeT* BSTNodeT::GetLeft() const {
      return left_;
    }
    
    BSTNodeT* BSTNodeT::GetRight() const {
      return right_;
    }
    
    int BSTNodeT::GetCount() {
      return count_;
    }
    ~~~Tree~~~

    Code:
    #ifndef BS_TREET_H
    #define BS_TREET_H
    #include <string>
    #include <climits>
    #include "bs_nodet.h"
    
    template <typename T>
    class BSTreeT {
     public:
      BSTreeT();
      ~BSTreeT();
      int GetSize() const;
      void Clear();
      int Insert(T i);
      bool Exists (T i);
      int Remove(T i);
      T Get (T i);
      std::string ToStringForwards() const;
      std::string ToStringBackwards() const;
     private:
      BSTNodeT<T>* root_;
      unsigned int size_;
      void Clear (BSTNodeT<T>*& node);
      int Insert (T i, BSTNodeT<T>*& node);
      bool Exists (T i, BSTNodeT<T>* node);
      int Remove (T i, BSTNodeT<T>* node);
      T Get (T i, BSTNodeT<T>* node);
      std::string ToStringForwards (BSTNodeT<T>* node) const;
      std::string ToStringBackwards (BSTNodeT<T>* node) const;
    };
    
    #endif /* BS_TREET_H */
    Code:
    #include "bs_treet.h"
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cctype>
    #include <sstream>
    using std::cin;
    using std::cout;
    using std::endl;
    using std::string;
    using std::stringstream;
    
    template <typename T>
    BSTreeT<T>::BSTreeT() {
      root_ = NULL;
      size_ = 0;
    }
    
    template <typename T>
    BSTreeT<T>::~BSTreeT() {
      Clear();
    }
    
    template <typename T>
    int BSTreeT<T>::GetSize() const {
      return size_;
    }
    
    template <typename T>
    void BSTreeT<T>::Clear() {
      Clear(root_);
      size_ = 0;
    }
    
    template <typename T>
    int BSTreeT<T>::Insert(T i) {
      return Insert(i, root_);
    }
    
    template <typename T>
    bool BSTreeT<T>::Exists (T i) {
      return Exists(i, root_);
    }
    
    template <typename T>
    int BSTreeT<T>::Remove(T i) {
      return Remove(i, root_);
    }
    
    template <typename T>
    T BSTreeT<T>::Get (T i) {
        return Get(i, root_);
    }
    
    template <typename T>
    std::string BSTreeT<T>::ToStringForwards() const {
      return ToStringForwards(root_);
    }
    
    template <typename T>
    std::string BSTreeT<T>::ToStringBackwards() const {
      return ToStringBackwards(root_);
    }
    
    template <typename T>
    void BSTreeT<T>::Clear (BSTNodeT<T>*& node) {
      if (node != NULL) {
      Clear(node->GetLeft());
      Clear(node->GetRight());
      delete node;
      node = NULL;
      }
    }
    
    template <typename T>
    int BSTreeT<T>::Insert (T i, BSTNodeT<T>*& node) {
      int count = 0;
      if (node == NULL) {
        node = new BSTNodeT<T>(i);
        size_++;
        count++;
      } else if (node->GetContents() > i) {
        return Insert(i, node->GetLeft());
      } else if (node->GetContents() < i) {
        return Insert(i, node->GetRight());
      } else {
        node->IncrementCount();
        count++;
      }
      return count;
    }
    
    template <typename T>
    bool BSTreeT<T>::Exists (T i, BSTNodeT<T>* node) {
      if (node != NULL) {
        Exists(node->GetLeft());
        if (node == i) {
          return true;
        }
        Exists(node->GetRight());
      }
      return false; 
    }
    
    template <typename T>
    int BSTreeT<T>::Remove (T i, BSTNodeT<T>* node) {
      if (node != NULL) {
        Remove(node->GetLeft());
        if (node == i) {
          if (node == 1) {
            delete node;
            node = NULL;
            return 0;
          } else {
            node->DecrementCount();
            return node;
          }
        }
        Remove(node->GetRight());
      }
      return -1; 
    }
    
    template <typename T>
    T BSTreeT<T>::Get (T i, BSTNodeT<T>* node) {
      if (node != NULL) {
        Get(node->GetLeft());
        if (node == i) {
          return node;
        }
        Get(node->GetRight());
      }
      return NULL; 
    }
    
    template <typename T>
    string BSTreeT<T>::ToStringForwards (BSTNodeT<T>* node) const {
      if (node != NULL) {
        std::ostringstream ss;
        ss << ToStringForwards(node->GetLeft());
        ss << node->GetContents() << " ";
        ss << ToStringForwards(node->GetRight());
        return ss.str();
      }
      return ""; 
    }
    
    template <typename T>
    string BSTreeT<T>::ToStringBackwards (BSTNodeT<T>* node) const {
      if (node != NULL) {
        std::ostringstream ss;
        ss << ToStringBackwards(node->GetRight());
        ss << node->GetContents() << " ";
        ss << ToStringBackwards(node->GetLeft());
        return ss.str();
      }
      return ""; 
    }
    ~~~Compiler Error~~~

    Code:
    $ g++ bs_treet.cpp assignment_5_unit_test.cpp
    assignment_5_unit_test.cpp: In function ‘void UnitTest()’:
    assignment_5_unit_test.cpp:50:25: error: invalid conversion from ‘BSTNodeT<int>*’ to ‘int’ [-fpermissive]
       inode1.SetLeft(&inode2);
                             ^
    In file included from bs_treet.h:5:0,
                     from assignment_5_unit_test.cpp:10:
    bs_nodet.h:10:3: note: initializing argument 1 of ‘BSTNodeT<T>::BSTNodeT(T) [with T = int]’
       BSTNodeT(T contents);
       ^
    assignment_5_unit_test.cpp:52:26: error: invalid conversion from ‘BSTNodeT<int>*’ to ‘int’ [-fpermissive]
       inode1.SetRight(&inode3);
                              ^
    In file included from bs_treet.h:5:0,
                     from assignment_5_unit_test.cpp:10:
    bs_nodet.h:10:3: note: initializing argument 1 of ‘BSTNodeT<T>::BSTNodeT(T) [with T = int]’
       BSTNodeT(T contents);
       ^
    assignment_5_unit_test.cpp:69:25: error: invalid conversion from ‘BSTNodeT<char>*’ to ‘char’ [-fpermissive]
       cnode1.SetLeft(&cnode2);
                             ^
    In file included from bs_treet.h:5:0,
                     from assignment_5_unit_test.cpp:10:
    bs_nodet.h:10:3: note: initializing argument 1 of ‘BSTNodeT<T>::BSTNodeT(T) [with T = char]’
       BSTNodeT(T contents);
       ^
    assignment_5_unit_test.cpp:71:26: error: invalid conversion from ‘BSTNodeT<char>*’ to ‘char’ [-fpermissive]
       cnode1.SetRight(&cnode3);
                              ^
    In file included from bs_treet.h:5:0,
                     from assignment_5_unit_test.cpp:10:
    bs_nodet.h:10:3: note: initializing argument 1 of ‘BSTNodeT<T>::BSTNodeT(T) [with T = char]’
       BSTNodeT(T contents);
       ^
    assignment_5_unit_test.cpp:89:25: error: no matching function for call to ‘BSTNodeT<std::basic_string<char> >::SetLeft(BSTNodeT<std::basic_string<char> >*)’
       snode1.SetLeft(&snode2);
                             ^
    assignment_5_unit_test.cpp:89:25: note: candidate is:
    In file included from bs_treet.h:5:0,
                     from assignment_5_unit_test.cpp:10:
    bs_nodet.h:13:8: note: void BSTNodeT<T>::SetLeft(BSTNodeT<T>) [with T = std::basic_string<char>]
       void SetLeft(BSTNodeT node);
            ^
    bs_nodet.h:13:8: note:   no known conversion for argument 1 from ‘BSTNodeT<std::basic_string<char> >*’ to ‘BSTNodeT<std::basic_string<char> >’
    assignment_5_unit_test.cpp:91:26: error: no matching function for call to ‘BSTNodeT<std::basic_string<char> >::SetRight(BSTNodeT<std::basic_string<char> >*)’
       snode1.SetRight(&snode3);
                              ^
    assignment_5_unit_test.cpp:91:26: note: candidate is:
    In file included from bs_treet.h:5:0,
                     from assignment_5_unit_test.cpp:10:
    bs_nodet.h:14:8: note: void BSTNodeT<T>::SetRight(BSTNodeT<T>) [with T = std::basic_string<char>]
       void SetRight(BSTNodeT node);
            ^
    bs_nodet.h:14:8: note:   no known conversion for argument 1 from ‘BSTNodeT<std::basic_string<char> >*’ to ‘BSTNodeT<std::basic_string<char> >’
    assignment_5_unit_test.cpp:143:29: error: invalid conversion from ‘int’ to ‘BSTNodeT<int>*’ [-fpermissive]
       tree_pointer = tree.Get(50);
                                 ^
    assignment_5_unit_test.cpp:146:28: error: invalid conversion from ‘int’ to ‘BSTNodeT<int>*’ [-fpermissive]
       tree_pointer = tree.Get(0);
                                ^

  3. #63
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Erik, ignore the tests for now. Just make your tree and do your own small tests. For example, use your test graph and delete a node. Then print the tree. Does it look like you expect it to? If not, it's time to launch the debugger and find the error.
    The current code is a mess because it seems you don't understand what you're doing. I can't even understand what the remove function is supposed to return. Start small. Implement as you go and do it right.
    Remove all code (comment it out) and implement only the minimum necessary to make it compile. Then implement one function, test it, and when it's working as it should, tackle the next.
    When you've finished adding everything, THEN you can use the testing code to test it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #64
    Registered User
    Join Date
    Feb 2015
    Posts
    225
    My apologies, my instructor has been having me use this node file for several labs now and said it'd work well with this assignment too, but I overlooked some changes that would be needed to fit with a template tree. I made several edits, but the compiler is giving me a message...I think it's referring to a lack of main method, but I'm not sure.

    Revised Node:

    Code:
    #ifndef BST_NODET_H
    #define BST_NODET_H
    #include <string>
    #include <climits>
    
    template <typename T>
    class BSTNodeT {
    public:
      BSTNodeT();
      BSTNodeT(T contents);
      ~BSTNodeT();
      void SetContents(T contents);
      void SetLeft(BSTNodeT<T>* node);
      void SetRight(BSTNodeT<T>* node);
      void IncrementCount();
      void DecrementCount();
      T GetContents() const;
      BSTNodeT* GetLeft() const;
      BSTNodeT* GetRight() const;
      int GetCount();
    private:
      T contents_;
      BSTNodeT<T>* left_;
      BSTNodeT<T>* right_;
      int count_;
    };
    
    #endif /* BST_NODET_H */
    Code:
    #include "bst_nodet.h"
    #include <iostream>
    #include <string>
    #include <sstream>
    using std::string;
    using std::stringstream;
    
    template <typename T>
    BSTNodeT<T>::BSTNodeT() {
      left_ = NULL;
      right_ = NULL;
      contents_ = T();
      count_ = 0;
    }
    
    template <typename T>
    BSTNodeT<T>::BSTNodeT(T contents) {
      left_ = NULL;
      right_ = NULL;
      contents_ = contents;
      count_ = 0;
    }
    
    template <typename T>
    BSTNodeT<T>::~BSTNodeT() {
      left_ = NULL;
      right_ = NULL;
    }
    
    template <typename T>
    void BSTNodeT<T>::SetContents(T contents) {
      contents_ = contents;
    }
    
    template <typename T>
    void BSTNodeT<T>::SetLeft(BSTNodeT<T>* node) {
      left_ = node;
    }
    
    template <typename T>
    void BSTNodeT<T>::SetRight(BSTNodeT<T>* node) {
      right_ = node;
    }
    
    template <typename T>
    void BSTNodeT<T>::IncrementCount() {
      count_++;
    }
    
    template <typename T>
    void BSTNodeT<T>::DecrementCount() {
      count_--;
    }
    
    template <typename T>
    T BSTNodeT<T>::GetContents() const {
      return contents_;
    }
    
    template <typename T>
    BSTNodeT<T>* BSTNodeT<T>::GetLeft() const {
      return left_;
    }
    
    template <typename T>
    BSTNodeT<T>* BSTNodeT<T>::GetRight() const {
      return right_;
    }
    
    template <typename T>
    int BSTNodeT<T>::GetCount() {
      return count_;
    }
    Compiler:

    Code:
    $ g++ bst_nodet.cpp bst_nodet.h
    /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../lib/libcygwin.a(libcmain.o): In function `main':
    /usr/src/debug/cygwin-1.7.33-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain'
    /usr/src/debug/cygwin-1.7.33-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
    collect2: error: ld returned 1 exit status
    I'm fairly sure this isn't something to worry about, but I need to update the code to keep things current, so I may as well make sure.

    Alot of the issues with the other compile error are gone, but this remains:

    Code:
    $ g++ bs_treet.cpp assignment_5_unit_test.cpp
    assignment_5_unit_test.cpp: In function ‘void UnitTest()’:
    assignment_5_unit_test.cpp:143:29: error: invalid conversion from ‘int’ to ‘BSTN    odeT<int>*’ [-fpermissive]
       tree_pointer = tree.Get(50);
                                 ^
    assignment_5_unit_test.cpp:146:28: error: invalid conversion from ‘int’ to ‘BSTN    odeT<int>*’ [-fpermissive]
       tree_pointer = tree.Get(0);
    The tree is still the same and while I acknowledge the possibility of misunderstanding the directions and some points, I don't see why this function in particular would have trouble with ints...

  5. #65
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I do not see Get() function in your template while UnitTest() is trying to call it - means you forgot to implement it.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #66
    Registered User
    Join Date
    Feb 2015
    Posts
    225
    Quote Originally Posted by vart View Post
    I do not see Get() function in your template while UnitTest() is trying to call it - means you forgot to implement it.
    Isn't this implementing it?

    Code:
    template <typename T>
    T BSTreeT<T>::Get (T i) {
        return Get(i, root_);
    }
    
    
    
    template <typename T>
    
    T BSTreeT<T>::Get (T i, BSTNodeT<T>* node) {
      if (node != NULL) {
        Get(node->GetLeft());
        if (node == i) {
          return node;
        }
        Get(node->GetRight());
      }
      return NULL; 
    }

  7. #67
    Registered User
    Join Date
    Feb 2015
    Posts
    225
    Compiler error is still the same, but I editted the tree cpp file a bit.

    Code:
    #include "bs_treet.h"
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cctype>
    #include <sstream>
    using std::cin;
    using std::cout;
    using std::endl;
    using std::string;
    using std::stringstream;
    
    template <typename T>
    BSTreeT<T>::BSTreeT() {
      root_ = NULL;
      size_ = 0;
    }
    
    template <typename T>
    BSTreeT<T>::~BSTreeT() {
      Clear();
    }
    
    template <typename T>
    int BSTreeT<T>::GetSize() const {
      return size_;
    }
    
    template <typename T>
    void BSTreeT<T>::Clear() {
      Clear(root_);
      size_ = 0;
    }
    
    template <typename T>
    int BSTreeT<T>::Insert(T i) {
      return Insert(i, root_);
    }
    
    template <typename T>
    bool BSTreeT<T>::Exists (T i) {
      return Exists(i, root_);
    }
    
    template <typename T>
    int BSTreeT<T>::Remove(T i) {
      return Remove(i, root_);
    }
    
    template <typename T>
    T BSTreeT<T>::Get (T i) {
        return Get(i, root_);
    }
    
    template <typename T>
    std::string BSTreeT<T>::ToStringForwards() const {
      return ToStringForwards(root_);
    }
    
    template <typename T>
    std::string BSTreeT<T>::ToStringBackwards() const {
      return ToStringBackwards(root_);
    }
    
    template <typename T>
    void BSTreeT<T>::Clear (BSTNodeT<T>*& node) {
      if (node != NULL) {
      Clear(node->GetLeft());
      Clear(node->GetRight());
      delete node;
      node = NULL;
      }
    }
    
    template <typename T>
    int BSTreeT<T>::Insert (T i, BSTNodeT<T>*& node) {
      int count = 0;
      if (node == NULL) {
        node = new BSTNodeT<T>(i);
        size_++;
        count++;
      } else if (node->GetContents() > i) {
        return Insert(i, node->GetLeft());
      } else if (node->GetContents() < i) {
        return Insert(i, node->GetRight());
      } else {
        node->IncrementCount();
        count++;
      }
      return count;
    }
    
    template <typename T>
    bool BSTreeT<T>::Exists (T i, BSTNodeT<T>* node) {
      if (node != NULL) {
        Exists(node->GetLeft());
        if (node == i) {
          return true;
        }
        Exists(node->GetRight());
      }
      return false; 
    }
    
    template <typename T>
    int BSTreeT<T>::Remove (T i, BSTNodeT<T>* node) {
      BSTNodeT<T>* temp;
      T min;
      if (node != NULL) {
        if (node->GetContents() == i) {
          if ((node->GetLeft() == NULL) && node->GetRight() == NULL) {
            if (i == 1) {
              delete node;
              node = NULL;
              size_--; 
              return 0;
            } else {
              node->DecrementCount();
              return node->GetContents();
            }
          } else if ((node->GetLeft() != NULL) && (node->GetRight()) == NULL) {
            if (i == 1) {
              delete node;
              node = NULL;
              size_--; 
              return 0;
            } else {
              node->DecrementCount();
              return node->GetContents();
            }
          } else if ((node->GetLeft() == NULL) && (node->GetRight()) != NULL) {
            if (i == 1) {
              delete node;
              node = NULL;
              size_--; 
              return 0;
            } else {
              node->DecrementCount();
              return node->GetContents();
            }
          } else {
            if (i == 1) {
              delete node;
              node = NULL;
              size_--; 
              return 0;
            } else {
              node->DecrementCount();
              return node->GetContents();
            }
          }
        } else if (node->GetContents() > i) {
        return Remove(i, node->GetLeft());
        } else if (node->GetContents() < i) {
        return Remove(i, node->GetRight());
        }
      }
      return -1;
    }
    
    template <typename T>
    T BSTreeT<T>::Get (T i, BSTNodeT<T>* node) {
      if (node != NULL) {
        Get(node->GetLeft());
        if (node == i) {
          return node->GetContents();
        }
        Get(node->GetRight());
      }
      return NULL; 
    }
    
    template <typename T>
    string BSTreeT<T>::ToStringForwards (BSTNodeT<T>* node) const {
      if (node != NULL) {
        std::ostringstream ss;
        ss << ToStringForwards(node->GetLeft());
        ss << node->GetContents() << " ";
        ss << ToStringForwards(node->GetRight());
        return ss.str();
      }
      return ""; 
    }
    
    template <typename T>
    string BSTreeT<T>::ToStringBackwards (BSTNodeT<T>* node) const {
      if (node != NULL) {
        std::ostringstream ss;
        ss << ToStringBackwards(node->GetRight());
        ss << node->GetContents() << " ";
        ss << ToStringBackwards(node->GetLeft());
        return ss.str();
      }
      return ""; 
    }
    
    template <typename T>
    T BSTreeT<T>::FindMin(BSTNodeT<T>* node) const {
      if (node != NULL) {
        if (node->GetLeft() == NULL) {
          return node->GetContents();
        } else {
          return FindMin(node->GetLeft());
        }
      }
      return T();
    }

  8. #68
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Have you even tried to compile this code? Have you even tried to run this code? Have you even tried to run some of your algorithms on pen and paper? Take your FindMin. What if the minimum is in node E? Have you even given an attempt to try a debugger?
    Are you trolling us? Are you ignoring us? What? Why is it that you still haven't even attempted to do some proper fixes to the code without dumping it on us? Are you just randomly writing stuff without knowing what you're doing?
    Take FindMin. Describe how the function works by doing it step by step. What does it return? What if the min is in node E? How does it work then? What does it return? Is it right? Why or why not?
    Take ToStringBackwards. Assign some random values to each node. Tell us, step by step, how it generates a string and returns it. What will be in this string? How does the function work? Does it work? Why or why not?

    Also when compiling, ensure you compile all the source files, e.g.:
    g++ a.cpp b.cpp c.cpp -o my_exe.exe

    Do NOT leave out any files, especially not a file with main in it!
    I expect you to compile the code properly, and when it compiles, run it using a debugger. If code doesn't compile, then figure out WHY. A lot of it has to do because you don't to understand WHAT your functions are supposed to return.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #69
    Registered User
    Join Date
    Feb 2015
    Posts
    225
    ...Actually, yes, I am trying to compile it right now.

    I also rewrote the code without templates to try and make it easier for myself and I have been able to get all the functions to compile except for "Get". I compiled and tested them and they all worked in a situation without templates, although, regardless of where I set it up, I haven't gotten Get to work. I realize I forgot to put the node file in that particular instance, but when I compile it with the node, it doesn't work.

  10. #70
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I think Elysia is getting frustrated because you are forgetting things obviously stated in your requirements.

    Quote Originally Posted by the assignment
    Member Function 6:
    Named Get. Searches for a particular value. Returns a pointer to the node if found otherwise returns NULL.
    It's when people stop reading posts, links, and their own assignments that we really stop caring so much about your problem.

  11. #71
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I am also frustrated because many of these function implementations make absolutely no sense which you'd see if you would just try to execute an example by hand. Even if not, it would be extremely clear if you used a debugger to step through the code.
    To me, it seems like you're just dumping code on us and expecting us to fix it.

    I realize I forgot to put the node file in that particular instance, but when I compile it with the node, it doesn't work.
    Doesn't help if we don't get compile errors and source. But the way, really, is to forget the test file until you've actually managed to complete the implementation. You're bogged down by so many errors that you can't actually compile or run the code!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #72
    Registered User
    Join Date
    Feb 2015
    Posts
    225
    @Elysia

    I'm sorry. I know I'm really testing your patience, but I've tried the debuggers and I've followed the guides, but I'm really struggling to understand what the problem is sometimes.

    With that said, It has helped me in some ways and I have managed to rebuild a lot of the code and test a incomplete copy, but in some cases I'm just really stuck and debugger or no debugger I genuinely can't tell what the problem is.

    And...I'm just compiling it as I've been instructed to. I'm fairly certain I need to compile it with the test, because from what I've been told (and from what I've seen) the compiler will just reject my code for it's lack of main method until I compile it with the test. If I misunderstood something, I apologize.

    Quote Originally Posted by whiteflags View Post
    I think Elysia is getting frustrated because you are forgetting things obviously stated in your requirements.


    It's when people stop reading posts, links, and their own assignments that we really stop caring so much about your problem.
    I've actually been trying to. Originally I tried "return node", but that didn't work. I also tried changing it to

    Code:
    BSTNodeT<T>* Get (T i, BSTNodeT<T>* node);
    And returning node, but then I got this very bizarre compiler error that I couldn't even begin to understand....

    Code:
    $ g++ bs_treet.cpp bst_nodet.cpp assignment_5_unit_test.cpp
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x13f): undefined reference to `BSTNodeT<int>::BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x13f):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x150): undefined reference to `BSTNodeT<int>::BSTNodeT(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x150):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::BSTNodeT(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x161): undefined reference to `BSTNodeT<int>::BSTNodeT(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x161):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::BSTNodeT(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1fa): undefined reference to `BSTNodeT<int>::GetContents() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1fa):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::GetContents() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x317): undefined reference to `BSTNodeT<int>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x317):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x435): undefined reference to `BSTNodeT<int>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x435):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x553): undefined reference to `BSTNodeT<int>::GetContents() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x553):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::GetContents() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x671): undefined reference to `BSTNodeT<int>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x671):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x78f): undefined reference to `BSTNodeT<int>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x78f):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x824):  undefined reference to  `BSTNodeT<int>::SetLeft(BSTNodeT<int>*)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x824):  relocation truncated to fit: R_X86_64_PC32 against undefined symbol  `BSTNodeT<int>::SetLeft(BSTNodeT<int>*)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x8bd): undefined reference to `BSTNodeT<int>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x8bd): additional relocation overflows omitted from the output
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x959):  undefined reference to  `BSTNodeT<int>::SetRight(BSTNodeT<int>*)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x9f2): undefined reference to `BSTNodeT<int>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xaab): undefined reference to `BSTNodeT<char>::BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xabc): undefined reference to `BSTNodeT<char>::BSTNodeT(char)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xacd): undefined reference to `BSTNodeT<char>::BSTNodeT(char)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xb65): undefined reference to `BSTNodeT<char>::GetContents() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xc81): undefined reference to `BSTNodeT<char>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xd9e): undefined reference to `BSTNodeT<char>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xebc): undefined reference to `BSTNodeT<char>::GetContents() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0xfd9): undefined reference to `BSTNodeT<char>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x10f7): undefined reference to `BSTNodeT<char>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x118b):  undefined reference to  `BSTNodeT<char>::SetLeft(BSTNodeT<char>*)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1223): undefined reference to `BSTNodeT<char>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x12be):  undefined reference to  `BSTNodeT<char>::SetRight(BSTNodeT<char>*)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1356): undefined reference to `BSTNodeT<char>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1410): undefined reference to `BSTNodeT<std::string>::BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1455):  undefined reference to  `BSTNodeT<std::string>::BSTNodeT(std::string)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x14b8):  undefined reference to  `BSTNodeT<std::string>::BSTNodeT(std::string)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1576):  undefined reference to `BSTNodeT<std::string>::GetContents()  const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x16b3): undefined reference to `BSTNodeT<std::string>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x17d1):  undefined reference to `BSTNodeT<std::string>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x18f9):  undefined reference to `BSTNodeT<std::string>::GetContents()  const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1a39): undefined reference to `BSTNodeT<std::string>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1b5a):  undefined reference to `BSTNodeT<std::string>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1bf2):  undefined reference to  `BSTNodeT<std::string>::SetLeft(BSTNodeT<std::string>*)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1c8b): undefined reference to `BSTNodeT<std::string>::GetLeft() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1d2d):  undefined reference to  `BSTNodeT<std::string>::SetRight(BSTNodeT<std::string>*)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1dc6):  undefined reference to `BSTNodeT<std::string>::GetRight() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1e86): undefined reference to `BSTreeT<int>::BSTreeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x1f60): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2010): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2055): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2107):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x214c):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2273): undefined reference to `BSTreeT<int>::Insert(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2394): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x245b): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x24a0): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2552):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2597):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x26be): undefined reference to `BSTreeT<int>::Insert(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x27df): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x28a6): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x28eb): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x29b3):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x29f8):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2b1f): undefined reference to `BSTreeT<int>::Insert(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2c40): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2d07): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2d4c): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2e14):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2e59):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x2f80): undefined reference to `BSTreeT<int>::Insert(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x30a1): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3168): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x31ad): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3275):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x32ba):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x33e1): undefined reference to `BSTreeT<int>::Exists(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3501): undefined reference to `BSTreeT<int>::Exists(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3597): undefined reference to `BSTreeT<int>::Get(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x363a): undefined reference to `BSTNodeT<int>::GetContents() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x36d3): undefined reference to `BSTreeT<int>::Get(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3892): undefined reference to `BSTreeT<int>::Remove(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x39b3): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3a7a): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3abf): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3b87):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3bcc):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3cf3): undefined reference to `BSTreeT<int>::Remove(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3e13): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3eda): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3f1f): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x3fe7):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x402c):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4153): undefined reference to `BSTreeT<int>::Remove(int)'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x41e7): undefined reference to `BSTreeT<int>::Clear()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4283): undefined reference to `BSTreeT<int>::GetSize() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4349): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x438e): undefined reference to `BSTreeT<int>::ToStringForwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4440):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4485):  undefined reference to `BSTreeT<int>::ToStringBackwards() const'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x466b): undefined reference to `BSTreeT<int>::~BSTreeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x467a): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4689): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4695): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x46a1): undefined reference to `BSTNodeT<char>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x46ad): undefined reference to `BSTNodeT<char>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x46b8): undefined reference to `BSTNodeT<char>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x46c4): undefined reference to `BSTNodeT<int>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x46d0): undefined reference to `BSTNodeT<int>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x46dc): undefined reference to `BSTNodeT<int>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4e6e): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x4ead): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x615b): undefined reference to `BSTreeT<int>::~BSTreeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x616f): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x6183): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x6194): undefined reference to `BSTNodeT<std::string>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x61a5): undefined reference to `BSTNodeT<char>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x61b6): undefined reference to `BSTNodeT<char>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x61c6): undefined reference to `BSTNodeT<char>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x61d7): undefined reference to `BSTNodeT<int>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x61e8): undefined reference to `BSTNodeT<int>::~BSTNodeT()'
    /tmp/ccYKpK9e.o:assignment_5_unit_test.cpp:(.text+0x61f9): undefined reference to `BSTNodeT<int>::~BSTNodeT()'
    collect2: error: ld returned 1 exit status

  13. #73
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Erik Ingvoldsen View Post
    I'm sorry. I know I'm really testing your patience, but I've tried the debuggers and I've followed the guides, but I'm really struggling to understand what the problem is sometimes.

    With that said, It has helped me in some ways and I have managed to rebuild a lot of the code and test a incomplete copy, but in some cases I'm just really stuck and debugger or no debugger I genuinely can't tell what the problem is.
    You need to be forthcoming with these kinds of things. If you've tried something and it didn't work, then tell us what you've done and why it didn't work out for you. If you get stuck using a debugger, someone could lend a hand, but if you don't mention that you've used one, everyone will assume you haven't. This is mostly because you've seemed to just "ignore" posts saying you should use a debugger, or test the problem by hand, etc. It seems to us, then, that you're ignoring such posts.

    Alright, but it's good that you're forthcoming now, because it tells me that you are passionate about doing this. Some people plain out just ignore certain advice and dump code on us. It has happened in the past and will likely continue in the future.

    And...I'm just compiling it as I've been instructed to. I'm fairly certain I need to compile it with the test, because from what I've been told (and from what I've seen) the compiler will just reject my code for it's lack of main method until I compile it with the test. If I misunderstood something, I apologize.
    Yeah, it will reject your code if you don't have a main function, but you can always write your own. Which I would advise doing until you've finished building and testing your implementation.

    I've actually been trying to. Originally I tried "return node", but that didn't work. I also tried changing it to

    Code:
    BSTNodeT<T>* Get (T i, BSTNodeT<T>* node);
    And returning node, but then I got this very bizarre compiler error that I couldn't even begin to understand....
    Compilation is done in two stages: compilation and linking. Compilation takes every source files, parses it and outputs some kind of object file. The linker takes every object file and puts them together into a single file.
    As a consequence of this, if you call a function that resides in another source file than the one you're calling it from, the compiler will go "oh hey, this is in another file, so I'm just going to ignore that for now." Then the linker comes and tries to find this function and fixes the code so it calls the right function. But if that function does not actually exist, the compiler goes "oh hey, this is in another file, so I'm just going to ignore that for now," but the linker gets confused and says "hey, I can't find this function."
    Unfortunately it's being very cryptic about it. But this is what the "undefined reference" means. "undefined reference to `BSTNodeT<int>::BSTNodeT()'" just means the linker can't find BSTNodeT<int>::BSTNodeT(). There are usually three common cases for this kind of problem:
    - You declared that a function exists but forgot to implement it.
    - The declaration does not match the implementation. For example, wrong return type, wrong argument types, wrong calling convention, etc.
    - You tried to put templates into source files. Always put templates into headers and include them. Do not separate declaration and definition by putting the implementation into a source file.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #74
    Registered User
    Join Date
    Feb 2015
    Posts
    225
    Quote Originally Posted by Elysia View Post
    - You tried to put templates into source files. Always put templates into headers and include them. Do not separate declaration and definition by putting the implementation into a source file.
    That might be it. But to clarify, the source file is the cpp file, yes? Which means in this function,

    Code:
    template <typename T>
    void BSTreeT<T>::Clear() {
      Clear(root_);
      size_ = 0;
    }
    I should delete the top line because in the header I have this,

    Code:
    template <typename T>
    class BSTreeT {
    Right? Or is that just contemplating the class itself, and I still need to template all the functions inside?

  15. #75
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It means you should do
    Code:
    template<typename T>
    class foo
    {
        void bar() { /* my code */ }
        // ...
    }
    ...or...
    Code:
    template<typename T>
    class foo
    {
        void bar();
        // ...
    }
    
    template<typename T>
    void foo::bar() { /* my code here */ }
    
    //...
    All these lines of code must be in the header. Do not put them in a source file (.cpp).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Node Assignment
    By Erik Ingvoldsen in forum C++ Programming
    Replies: 48
    Last Post: 04-17-2015, 03:50 PM
  2. assignment of node in linked list
    By nutzu2010 in forum C Programming
    Replies: 8
    Last Post: 03-28-2011, 10:29 AM
  3. MSVC Template Constructor/Assignment Errors
    By LuckY in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:57 PM
  4. help with template class using a template node
    By aciarlillo in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2005, 05:46 PM
  5. Please help with template node class
    By aciarlillo in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2005, 03:45 PM