【问题标题】:initializing argument 1 of... [-fpermissive]初始化...的参数 1 [-fpermissive]
【发布时间】:2013-11-16 09:47:07
【问题描述】:

我是 C++ 新手,在 ubuntu 上使用 eclipse cdt 并在我的头文件中收到此错误:

initializing argument 1 of 'std::map<basic_string<char>,Supplier*> Engine::processSupplierFile(char*)' [-fpermissive]

我已经搜索过这个错误并发现了这个: Why am I getting error: initializing argument 1 of 'Item::Item(int)' [-fpermissive] in Eclipse when I try to compile my C++ code?

但它没有任何关于头文件错误的答案。

这里是头文件的代码:(供应商是一个简单的对象,包含两个字符串和一个双精度)

#ifndef Engine_H_
#define Engine_H_

#include "Ingredient.h"
#include "Product.h"
#include "Supplier.h"

#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

class Engine {
public:
    Engine();
    virtual ~Engine();
    string fileToString(string fileName);
    void processLoggerFile (char* fileName);
    string fileToString(char* fileName);
    vector<Product> processProductsFile(char* fileName, const map<string, Ingredient> &cheapestIngredients); 
    map<string, Supplier*> processSuppliersFile(char* fileName); // this line produces the error
    map<string, Ingredient> findCheapestPrices(vector<Supplier> &suppliers);
    map<string, Product*> createMenu(vector<Product>& products);
    void supplierPriceChange(vector<Product>& products, map<string,Product*>& menu,vector<Supplier>& suppliers, map<string, Ingredient> cheapestIngredients, string supName, string ingName, double newPrice);
};

#endif /* Engine_H_ */

有谁知道是什么导致了这个错误? 提前谢谢

编辑(supplier.h 添加)

/*
 * Supplier.h
 *
 *  Created on: Nov 10, 2013
 *      Author: tom
 */

#ifndef SUPPLIER_H_
#define SUPPLIER_H_

#include <string>

using namespace std;

class Supplier {
public:
    Supplier();
    Supplier(const Supplier& supplier);
    Supplier(string supName, string ingName, double price);
    Supplier& operator=(const Supplier& supplier);
    virtual ~Supplier();
    string getSupplierName() const;
    string getIngredientName() const;
    double getPrice() const;
    void setPrice(double price);

private:
    string _ingredientName;
    string _supplierName;
    double _price;

};

#endif /* SUPPLIER_H_ */

【问题讨论】:

  • 在这里转发声明供应商就足够了。我想这是一个循环依赖问题。您应该删除所有与问题相关的代码,但包括重构的必要位:What's a Supplier?
  • 关于头文件的两件事:使用保留标识符(数据字段名称以下划线开头,不允许这样做)。其次,不要在头文件中使用using namespace std
  • @Tom:有关 stefan 提到的问题的详细信息,请参阅这些 SO 文章:stackoverflow.com/questions/228783/…stackoverflow.com/questions/4872373/… 也就是说,我认为这些可能的问题与您的问题无关问题。
  • 这里很难找出问题的真正原因。请将您的代码减少到导致完全相同问题的最小代码示例。还要确保这是您的编译器输出的第一个错误(例如,对于 g++ 使用 -Wfatal-errors
  • processSuppliersFileprocessSupplierFile 不同,因此您没有发布真正的错误或没有发布真正的代码。并发布 whole 错误;它可能跨越两行或多行。

标签: c++ compiler-errors


【解决方案1】:

好的,我解决了。 此错误可能是由将非 const var 发送到 const 方法的实现引起的。 我在变量和方法中添加了一个常量,问题就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    相关资源
    最近更新 更多