简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM