Som*_*per 0 c++ typedef function-pointers linker-errors
我试图在C++中将函数作为参数传递.我一直收到LNK2019未解决的外部符号错误.
我已经读过这些,并且已经修复了这些,但我无法弄清楚我在这里做错了什么.
我的显示函数中的TreeItemType引用似乎发生了错误.
include "PhoneBook.h"
include "PhoneEntry.h"
include "bst.h"
using namespace std;
using namespace p04NS;
void display(TreeItemType& item);
int main() {
PhoneEntry test = PhoneEntry("first", "last", "618-580-0680");
bst * tree = new bst();
TreeItemType foo = TreeItemType(); // test type reference, no error
tree->insert(test);
tree->inorder(display);
system("pause");
return 0;
}
void display(TreeItemType& item){
cout << "hello worlds!";
}
Run Code Online (Sandbox Code Playgroud)
TreeItemType typedef在此处定义.
namespace p04NS {
typedef PhoneEntry TreeItemType;
typedef string KeyType;
// Pointer to a function that can be used to display the item.
typedef void (*FunctionType)(const TreeItemType& item);
class bst { //some codez }
}
Run Code Online (Sandbox Code Playgroud)
我尝试在main中使用这种类型,并没有收到任何错误.此外,它是否错误我是否注释掉该功能的使用.所以它似乎是我的函数定义的问题,而不是它的用法.
任何帮助表示赞赏.提前致谢!
void display(TreeItemType& item){
Run Code Online (Sandbox Code Playgroud)
和
typedef void (*FunctionType)(const TreeItemType& item);
Run Code Online (Sandbox Code Playgroud)
指出不同?提示,它以字母'c'开头.
但是,鉴于此代码不应编译.所以你也必须有其他一些问题.始终发布实际代码.
| 归档时间: |
|
| 查看次数: |
1552 次 |
| 最近记录: |