我有一个简单的函数,我简化为只返回一个虚拟列表(以确保它不是一些逻辑错误)
vector<AttrValue>* QueryEvaluator::getCandidateList(...) {
...
values.clear();
values.push_back(2);
values.push_back(3);
cout << "values is of size " << values.size() << endl;
return &values;
}
然后在 cppunit 测试中:
vector<AttrValue>* candidateList0 = evaluator->getCandidateList(cl, 0);
cout << candidateList0->size() << endl;
但问题是size()
,在测试中,即使cout
消息打印正确的大小 2,它也始终为 0。可能有什么问题?
我尝试了一个简单的程序,它似乎很好......
#include <iostream>
#include <vector>
using namespace std;
vector<int>* test() {
vector<int> vec { 2, 3, 6, 1, 2, 3 };
return &vec;
}
int main() {
cout << test()->size() << endl;
return 0;
}