1

I'm new to c++ and using eclipse cdt on ubuntu and getting this error in my header file:

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

I already searched for this error and found this: Why am I getting error: initializing argument 1 of 'Item::Item(int)' [-fpermissive] in Eclipse when I try to compile my C++ code?

but it didn't have any answers about the header file error.

here is the code of the header file: (Supplier is a simple object containing two string and a 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_ */

Does anyone knows what is causing this error? thanks in advance

EDIT (supplier.h added)

/*
 * 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_ */
Community
  • 1
  • 1
Tom
  • 1,203
  • 4
  • 21
  • 36
  • Forward declaring Supplier should suffice here. I guess it's a circular dependency issue. You should remove all code _not_ related to the issue, but include the necessary bits to reconstruct: What's a `Supplier`? – stefan Nov 16 '13 at 09:50
  • u r right, ill add it. – Tom Nov 16 '13 at 09:52
  • @stefan: presumably `Supplier` is declared in `Supplier.h`. – Michael Burr Nov 16 '13 at 09:52
  • @MichaelBurr Yeah and that's helpful in what way? I don't see `Supplier.h`. The error might be there. – stefan Nov 16 '13 at 09:53
  • 2
    Two things about your header files: You use reserved identifiers (you start the data field names with an underscore, you're not allowed to do that). Second, don't use `using namespace std` in header files. – stefan Nov 16 '13 at 09:55
  • i used underscores and using namespace in many others files and didnt get any error.. – Tom Nov 16 '13 at 09:58
  • @stefan: it's relevant because if `Supplier` weren't declared the compiler would complain that "'Supplier' was not declared" rather than the "initializing argument 1" error. – Michael Burr Nov 16 '13 at 09:59
  • @stefan Actually, these are legal. Names starting with an underscore followed by a lowercase letter are reserved in global scope only. So as member names, they are fine. – Angew is no longer proud of SO Nov 16 '13 at 10:00
  • @Tom: usually the "initializing argument 1 of" errors are accompanied by other errors - you should show those as well in your question (along with the code they reference). I suspect the real problem is at the location where you try to call `processSuppliersFile()` – Michael Burr Nov 16 '13 at 10:00
  • @MichaelBurr It's irrelevant without seeing the actual declaration. Why? Because now that we see it, it's not standard conforming code. That might be the issue. "When debugging, think like a compiler" – stefan Nov 16 '13 at 10:01
  • 1
    @Tom: see these SO articles for details on the issues stefan mentioned: http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier and http://stackoverflow.com/questions/4872373/why-is-including-using-namespace-into-a-header-file-a-bad-idea-in-c That said, I don't think those possible issues have anything to do with the problem in your question. – Michael Burr Nov 16 '13 at 10:15
  • 2
    It's hard to identify the real cause of problems here. Please reduce your code to the minimal code sample that causes the exact same issue. Also make sure it's the very first error your compiler outputs (E.g. for g++ use `-Wfatal-errors`) – stefan Nov 16 '13 at 10:18
  • 1
    `processSuppliersFile` is not the same as `processSupplierFile` so you're not posting the real error or not posting the real code. And post the _whole_ error; it may span two or more lines. – Lightness Races in Orbit Nov 16 '13 at 10:34
  • i typed the error manually. that's probably a typo. – Tom Nov 16 '13 at 10:47

1 Answers1

5

OK, i solved it. This error is probably caused by the implementation which sent a non const var to a const method. i added a const to the variable and to the method and the problem was solved.

Tom
  • 1,203
  • 4
  • 21
  • 36