c++linuxg++typedef

g++ error regarding undefined reference to typedef


i am trying to compile a simple test program, and one of the header files i am including has the following typedef

typedef const char* CharConst;
typedef unsigned int MyBool; 

later in the header file, some functions are defined using this typedef. stuff like:

MyBool add_att(CharConst attr, const char*);

i am getting an error when i try to make a call to this function, with a call like:

CharConst myconst = "some text";
const char* more_text = "more text";
add_att(myconst, more_text);

the error is: undefined reference to `MyClass::add_att(char const*, char const*)'

it seems that the compiler doesn't like the fact that the first argument has been typedef'd in the header file. but it doesn't mind the MyBool. the compiler only complains about the CharConst definition.

is there any easy way to fix this? any clues or hints on what i can do? i'm running gcc version 4.6.2


Solution

  • From the error it looks like add_att is a method of a class; I do not see an instance of your class to call the method. Consider this: MyClass *m = new MyClass(); m->add_att(....)

    Alternatively, ensure that the function is actually defined, not just prototyped. Also, this may not matter, but during the definition of the function - do you use the typedef in the function arguments? Actually that shouldn't matter... type is the same.