【发布时间】:2011-05-27 12:04:48
【问题描述】:
我想通过指针检索类函数的返回值。在这种情况下,返回值是一个向量(在类 vec 中定义)并由 GetA() 返回。但是,下面的代码会产生错误。您不能以这种方式使用指针来分配函数的值吗?
#include<cstdio>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include "model.h"
#include "vector.h"
int main (int argc, char *argv[]) {
//some code
model *thisModel;
thisModel = new model(name, outName, fileFormat);
vec a;
a = thisModel->GetA(); //this is line 264
GetA 函数在类模型中定义为:
vec model::GetA() {return a;}
我收到错误:main.cpp:264: error: no matching function for call to 'vec::vec(vec)'
一些背景知识:我正在将一些代码从在 Borland 上编译转换为 gcc(以前在 Borland 上运行良好)。我已经摆脱了大部分错误,但我仍然不明白为什么上面的代码不再有效。另外:
thisModel-> GetA(); //does not produce an error but does not return the vector I need
谢谢!
【问题讨论】: