I have a file A.cpp
which has the following lines:
#include"B.h"
int main(int argc, char **argv)
{
...
char *input_file = *argv;
B *definition = new B(input_file);
...
}
In B.h
, I have the following:
class B
{
public:
// Constructors
B(void);
B(const c开发者_如何学编程har *filename);
...
}
When I compile, I get the following error: undefined reference to 'B::B(char const*)'
Any suggestions on how to fix?
Thanks.
You need a definition for B::B(char const *)
. You have provided only a declaration for B::B(char const *)
, and the Linker is complaining that it can't actually find that function.
It seems like you specified the header for the function, but never actually wrote the body of the function.
You need to define the function I.E.
B::B(const char *filename){
// Do stuff
}
in B.cpp.
Your problem doesn't have anything to do with const correctness.
精彩评论