【发布时间】:2014-11-22 02:06:50
【问题描述】:
我必须创建一个内部定义为短值向量的类。向量初始大小为 40。现在,我必须创建一个构造函数,将用户输入的长整数转换为类对象。否则,向量的所有元素都应为 0。
我尝试编写代码,但可以写到这个级别,现在卡住了。 附言我是 C++ 初学者
class HugeInteger
{
public:
HugeInteger (long = 0);
void output (ostream& outs);
private:
vector<short> v;
};
/*HugeInteger::HugeInteger (long = 0)
{
int i=0;
for (i=0;i<40;i++)
{
v.push_back (0);
}
}*/
void HugeInteger ::output (ostream& outs)
{
int i = 0;
outs << "Values in the vector are initialized to" << endl;
while(i < 40)
{
outs << v[i] << "\t";
i++;
}
}
int main()
{
long integer;
cout << "Enter a long integer" << endl;
// for(int i=0;i<40;i++)
cin >> integer;
HugeInteger test (integer);
test.output(cout);
return 0;
}
出现以下错误:
错误 1 错误 LNK2019:未解析的外部符号“public: __thiscall HugeInteger::HugeInteger(long)”(??0HugeInteger@@QAE@J@Z) 在函数 _main 中引用
【问题讨论】:
标签: c++ class vector constructor