【发布时间】:2015-08-07 13:01:44
【问题描述】:
错误 C2661:'Stock::Stock':没有重载函数需要 2 个参数
我正在使用 Visual Studio 2012,仅供参考,每次尝试用类的对象填充向量时,我都会收到 C2661 错误:
void AFTS::createSys() {
AFTS::fs.assign(100, new Stock());
// the error occurs when calling the assign() function
}
这是保存向量的类:
class AFTS {
public:
std::vector<Stock> fs;
void createSys();
void addStock(Stock stock, int price);
void deleteStock(Stock stock);
int stockGetPrice(Stock stock);
void sellStock(Stock stock, int price);
void buyStock(Stock stock, int min, int max);
};
这是我试图填充向量的类:
class Stock {
public:
int price;
std::string tick;
};
起初我认为这可能是与包含头文件有关的错误,但我检查了多次,它们似乎是正确的,所以我不太明白我做错了什么导致这种情况。
【问题讨论】:
-
无法阅读文档,主要是...
-
我真的不确定你是如何从这段代码中得到 that 错误的。哦,好吧。
-
@Quentin:这段代码究竟是在哪里尝试使用两个参数调用
Stock构造函数? -
@LightnessRacesinOrbit 哦,我没有注意到消息的一部分很奇怪。我无法使用 MSVC 2013 (
error C2664: 'void std::vector<Foo,std::allocator<_Ty>>::assign(unsigned int,const Foo &)' : cannot convert argument 2 from 'Foo *' to 'const Foo &') 重现它。 MSVC 2012 错误? -
@Quentin OP 错误的可能性更大
标签: c++ class visual-studio-2012 vector