c++ - Linking error: undefined reference within the same class -


i getting following error g++ 4.9:

basis.cpp:16: undefined reference `basis::foo(int, int)' 

this header file:

#ifndef basis_h #define basis_h   #include "common.h" #include <math.h> #include "xdouble.h"  using namespace std;  class basis {  private:      int rank;     int dim;    public:      basis(); //empty constructor      basis(int r, int d); //default constructor      void foo(int a, int b);     void bar(int a, int b); };  #endif 

the basis.cpp file following:

#include "basis.h"  basis::basis() {     rank = 0;     dim = 0; }  basis::basis(int r, int d) // default constructor {     rank = r;     dim = d;  }  void basis::bar(int a, int b) {     void foo(int a, int b); }  void basis::foo(int a, int b) {  } 

even though i'm including basis.h file undefined reference error , can't understand why happening. doing wrong?

thanks

it looks copy , paste error. try this:

void basis::bar(int a, int b) {   foo(a, b); } 

you made mistake because copied , pasted definition of function foo in place wanted call function.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -