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
Post a Comment