对foo::bar static ofstream的未定义引用
Undefined reference to foo::bar static ofstream
我一直在尝试编译一个我花了三天时间构建的程序,但我不知道如何让它停止抛出错误。我一直得到编译错误"对Foo::bar的未定义引用",其中"bar"是在Foo.h文件中声明的静态ofstream。
foo。
Class Foo
{
public:
<insert methods>
private:
static ofstream& bar;
}
Foo.cpp
#include <iostream>
#include <fstream>
#include <sstream>
#include "EventReport.h"
using namespace std;
Foo::Foo()
{
bar.open("foobar.txt");
}
我一直在Foo.cpp中的"bar"上获得错误消息(文件中有多个)。知道为什么吗?
undefined reference to Foo::bar
这个错误意味着你告诉编译器这个对象存在…
class Foo {
static ofstream& bar;
};
…编译器决定使用它
但是你从来没有定义过。这是未定义的。
添加到Foo.cpp:
ofstream& Foo::bar = (something);
相关文章:
- 编译C++时未定义的引用
- vscode g++链路故障:体系结构x86_64的未定义符号
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 不知道某个东西是否被忽略会引入未定义的行为吗
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- c++11评估顺序(未定义的行为)
- 使用mysql c++连接器的未定义引用
- 从python调用openMP共享库时,未定义opnMP函数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 具有外部"c"和程序集的未定义函数
- 此增量后语句是否会导致未定义的行为?
- 尝试调用 .h 文件中定义的变量时出现变量未定义错误
- 在C++中使用内联方法时出现未定义的符号错误
- 对foo::bar static ofstream的未定义引用