【发布时间】:2015-01-27 21:40:41
【问题描述】:
当我使用以下语法传递向量的地址时:
void myfunction(std::vector<double>*);
int main()
{
std::vector<double> t;
myfunction(&t);
return 0;
}
void myfunction(std::vector<double> &v)
{
cout << "The function ran" <<endl;
}
我收到此错误,但不知道为什么。
pal-nat184-134-146:p25 pdevieti$ g++-4.9 test.cpp
Undefined symbols for architecture x86_64:
"myfunction(std::vector<double, std::allocator<double> >*)", referenced from:
_main in ccVmpacj.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
【问题讨论】:
-
您的
myfunction声明与定义不符。 -
在
myfunction的声明中,参数是一个指向双精度向量的指针,在定义中,您引用了相同类型的向量 -
您重新安装了操作系统和编译器,因为您遇到了链接器错误??!
-
您的代码正在调用一个不存在的函数。编译器不知道该函数实际上并不存在。该工作留给链接器,链接器在任何地方都找不到将指针指向向量的函数。所以你无缘无故做了所有这些卸载/重新安装游戏。
标签: c++ function vector osx-yosemite