我有一个类,其中 double vector 存储如下:
class clsHalfphoneUnitJoinFeatures : public CBaseStructure
{
private:
vector<double> m_content;
protected:
virtual void ProcessTxtLine(string line);
public:
vector<double> &Content();
void Add(vector<double> &jf);
};
但是,当我想添加一个新的 double vector 时,它不起作用:
void clsHalfphoneUnitJoinFeatures::ProcessTxtLine(string line)
{
line = CompactLine(line);
if (line == "")
return;
int b = 0;
int n = line.find("\t");
string s = "";
int idx = 0;
vector<double>jf;
jf.resize(16);
int i = 0;
for(;;)
{
if (n == -1)//if this is the last item in this line
{
s = line.substr(b,line.length()-b);
jf[i++] = atof(s.c_str());
break;
}
s = line.substr(b,n-b);
jf[i++] = atof(s.c_str());
b = n+1;
n = line.find("\t",b);
}
m_content.push_back(jf);
}
我得到的错误是
m_content.push_back(jf);
error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)': Conversion of parameter 1 from 'std::vector<_Ty>' in 'double &&' not possible
谁能告诉我哪里出错了?
谢谢!
最佳答案
jf
和 m_content
具有相同的类型,您不能将 jf
作为 m_content
的元素推送.
尝试改变
m_content.push_back(jf);
收件人:
m_content = jf;
如果你想要一个 double 类型的 vector ,你需要将m_content
声明为:
std::vector<std::vector<double> > m_content;
关于类中 vector 的 C++ vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17131259/