简体   繁体   English

关于未定义引用typedef的g ++错误

[英]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

typedef const char* CharConst;
typedef unsigned int MyBool; 

later in the header file, some functions are defined using this typedef. 稍后在头文件中,使用此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*)' 错误是:未定义对`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. 但它不介意MyBool。 the compiler only complains about the CharConst definition. 编译器仅抱怨CharConst定义。

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 我正在运行gcc版本4.6.2

From the error it looks like add_att is a method of a class; 从错误看来,add_att是一个类的方法。 I do not see an instance of your class to call the method. 我看不到您的类的实例来调用该方法。 Consider this: MyClass *m = new MyClass(); 考虑一下:MyClass * m = new MyClass(); m->add_att(....) 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? 另外,这可能并不重要,但是在函数定义期间-您是否在函数参数中使用typedef? Actually that shouldn't matter... type is the same. 其实没关系...类型是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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