【发布时间】:2018-09-03 19:37:48
【问题描述】:
编译器发出标识符“func”未定义的错误:
我不知道为什么会出现这个错误,因为我链接了头文件,这个函数的声明。我使用 Visual Studio 2017 社区。p>
我的代码:
foo.h
#pragma once
class Foo {
friend void func();
};
foo.cpp
#include "foo.h"
void func()
{
}
bar.h
#pragma once
class Bar {
void baz();
};
bar.cpp
#include "bar.h"
#include "foo.h"
void Bar::baz()
{
func(); // indentifier "func" is undefined
}
【问题讨论】:
-
编辑您的问题,显示错误,更正您的拼写。错了,标题不用于链接。
-
将声明
void func(void);添加到“foo.h”。 -
介意显示你定义函数的位置吗?因为它不在您的问题中,因此您的错误。
-
你的
foo类需要在类前声明func。使用前向声明。 -
这个
friend void func();不是声明。
标签: c++