gpt4 book ai didi

c++ - 初始化参数 1 of... [-fpermissive]

转载 作者:行者123 更新时间:2023-11-30 02:50:59 24 4
gpt4 key购买 nike

我是 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?

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

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

#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_ */

最佳答案

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

关于c++ - 初始化参数 1 of... [-fpermissive],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20016992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com