未解析的外部符号"public: class Foo __thiscall Bar::bu(char const *)"
Unresolved external symbol "public: class Foo __thiscall Bar::bu(char const *)"
这是我得到的。我正在尝试使用自定义构造函数在Bar中创建一个Foo实例。当我试图从Bar的构造函数调用构造函数时,我得到了一个未解析的外部构造函数。
class Foo
{
public:
// The custom constructor I want to use.
Foo(const char*);
};
class Bar
{
public:
Bar();
//The instance of Foo I want to use being declared.
Foo bu(const char*);
};
int main(int argc, char* args[])
{
return 0;
}
Bar::Bar()
{
//Trying to call Foo bu's constructor.
bu("dasf");
}
Foo::Foo(const char* iLoc)
{
}
这可能就是您想要的:
class Foo
{
public:
// The custom constructor I want to use.
Foo(const char*);
};
class Bar
{
public:
Bar();
//The instance of Foo I want to use being declared.
Foo bu; // Member of type Foo
};
int main(int argc, char* args[])
{
return 0;
}
Bar::Bar() : bu("dasf") // Create instance of type Foo
{
}
Foo::Foo(const char* iLoc)
{
}
关于这个声明:Foo bu(const char*);
这是一个名为bu
的成员函数的声明,它接受const char*
并返回Foo
。未解析的符号错误是因为您从未定义函数bu
,但您希望Foo
的实例不是函数。
看到评论后的其他方法:
class Foo
{
public:
// The custom constructor I want to use.
Foo(const char*);
};
class Bar
{
public:
Bar();
~Bar() { delete bu;} // Delete bu
//The instance of Foo I want to use being declared.
Foo *bu; // Member of type Foo
};
int main(int argc, char* args[])
{
return 0;
}
Bar::Bar() : bu(new Foo("dasf")) // Create instance of type Foo
{
}
Foo::Foo(const char* iLoc)
{
}
你的代码还有很多其他问题,也许读一本关于C++的书,比如《C++入门》是个好主意。
相关文章:
- ld: foo.o:foo.h:6 'bar' 的多重定义 foo.h:6: 首先在这里定义
- C++ "var foo = !!::bar()"语法?
- 诸如class bar *bar之类的指针的名称是什么?
- 无法将样式添加到QT Tab小部件中的选项卡(bar)和Tab(窗格)
- What does int foo = bar << ' '; mean in c++?
- 桌带(Explorer Bar)视觉样式
- Win32 API C++ Menu bar
- C++ vertical bar?
- 在"bar::foo"的定义中使用"foo"
- 为什么 foo(short int *) 和 bar(signed short *) 认为 QT 的签名不同
- 为什么我需要双括号在构造函数调用中,如:foo x((bar());
- g++ 拒绝,clang++ 接受: foo(x)( "bar" )( "baz" );
- 错误:类型为"bar&"的参数的默认参数<int>具有类型"bar<int>"
- 在 C++11 中使用 auto foo = "bar" vs std::string
- 为什么"Foo f(Bar());"可以是采用 Bar 类型并返回类型 Foo 的函数的声明?
- 将 'bar 类型的向量复制到 BYTE 类型的向量
- Blackberry 10正在安装.bar文件
- What is an `int foo::*bar::*`?
- 未解析的外部符号"public: class Foo __thiscall Bar::bu(char const *)"
- 使用 foo::bar 不会屏蔽 typedef-name ::bar?