Eri*_*ric 1 c++ std set pass-by-reference
鉴于以下先决条件:
shared.h
struct A {
int x;
int y;
}
typedef set<A> setOfA;
Run Code Online (Sandbox Code Playgroud)
implementation1.cpp
#include "shared.h"
void Implementation1::someFunction()
{
//...
setOfA setinstance;
//...
Implementation2* i = new Implementation2();
i->functionF(setinstance);
}
Run Code Online (Sandbox Code Playgroud)
implementation2.h
#include "shared.h"
void Implementation2::functionF(setOfA&);
Run Code Online (Sandbox Code Playgroud)
编辑:现在这应该更清楚......
我想传递setOfA给另一个类的另一个函数 - 一切都编译得很好.我收到以下链接器问题:
未定义的引用
'implementation::functionF(std::set<A, std::less<A>, std::allocator<A> >&)'
只是为了做对了 - 找不到实施,对吧?这不是一个typedef问题,因为一切都编译得很好......我在这里缺少什么?
链接器无法找到定义的void functionF(setOfA&);
在某个地方,你需要:
void Implementation2::functionF(setOfA&) {
...
}
Run Code Online (Sandbox Code Playgroud)
只是稍微详细说明一下,你不应该有一个实现上述代码的implementation2.cpp文件吗?
| 归档时间: |
|
| 查看次数: |
1062 次 |
| 最近记录: |