C++ linker error -


i"m having problem following program. program implements stack using linked list. i'm not showing code here because code fine. problem i'm having linking different files together.

i'm using ide run program. when run testintstacks.cpp, main method supposed call test() stackfunctions.cpp. test function (defined in stackfunctions.cpp), uses teststack class methods. i'm receiving error saying "linker error, push/pop not defined". i'm doing wrong? i'm sure it's namespace.

mystack.h ------------------------------------- namespace {     class node{         public :             char data;             stacknode* link;             stacknode(int v=0): data(v), link(null){ }     };      class mystack{         private:             node * top;          public:             mystack():top(null){ }             void push(int c);     }; }//namespace   //teststack.cpp -------------------------------------------------------------- #include "mystack.h"  namespace {     void mystack::push(int x)     {         stacknode *temp = new stacknode(x);         temp->link = top;         top = temp;     } }  //stackfunctions.cpp ----------------------------------------------------------- #include <iostream> #include "teststack.h"  using namespace std; using namespace a;  void test() {     mystack st;     st.push(1);     st.push(2);     st.push(3);     st.push(4); }  // testintstacks.cpp ---------------------------------------------------------------- // code testing teststack // namespace.  #include <iostream> #include <vector> using namespace std; #include "teststack" #include "stackfunctions.cpp"  void test(); int main() {     test();     system("pause");     return 0; } 

you defining push() , pop() methods in header file teststack.h, you've not provided implementations them in teststack.cpp. need add code push , pop operations on object.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -