繁体   English   中英

使用g ++ -c的c ++编译器错误:编译器将const string&识别为int

[英]c++ compiler error using g++ -c: compiler recognizes a const string& as int

我创建了一个具有构造函数的类Products

Product::Product(const int &num,const float &pr,const std::string &str):
number(num),price(pr),name(str)
{
}

当我使用g ++ -ci进行编译时,我在标头中有声明,并且在另一个源文件中有一个实现,但出现错误:

g++ -c Product.cpp
Product.cpp:14: error: prototype for 'Product::Product(const int&, const float&, const std::string&)' does not match any in class 'Product'
Product.h:5: error: candidates are: Product::Product(const Product&)
Product.h:10: error:                 Product::Product(const int&, const float&, int)

为什么会这样呢? 为什么编译器将const std :: string&替换为int?

问题是您忘记在标头中#include <string> ,从而导致g ++发出可疑的诊断,而对于无法理解的类型,该诊断将依赖于int

我通过删除同一文件夹中的一个名为Product.gch的文件解决了这个问题,我不知道它是如何解决的,但是它确实

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM