constructor - c++: No instance of overloaded function? -


// stock.h  #ifndef stock_h #define stock_h  // declare stock class class stock { private:     string stockexchange;     string symbol;     string company;     double price;     int shares; public:     stock();     stock(string stockexchange, string symbol, string company, double price, int shares);     void displaystockinfo();     void setstockinfo(string stockexchange, string symbol, string company, double price, int shares);     double getvalue();     bool operator < (stock & astock);     bool stock::operator > (stock & astock); };  #endif 

[break]

//main.cpp  #include <string> #include <iostream> #include <iomanip> #include <fstream>  #include "stock.h"  using std::string; using std::endl; using std::cout; using std::setw; using std::ifstream;   // ******************************* // stock class  stock::stock() {     stockexchange = "";     symbol = "";     company = "";     price = 0.0;     shares = 0; }  stock::stock(string stockexchange, string symbol, string company, double price, int shares) {     stockexchange = stockexchange;     symbol = symbol;     company = company;     price = price;     shares = shares; }   // end stock class // *******************************  ... 

my error says along lines of "no instance of overloaded function stock::stock(string stockexchange, string symbol, string company, double price, int shares) exists."

what doing wrong? see in header file.

you've not included <string> header file in stock.h header file, though you're using std::string in it. maybe causing error message (if case, bad message).

another problem in stock class definition, you've written this:

bool stock::operator > (stock & astock); 

which wrong. remove stock:: it, , make this:

bool operator > (const stock & astock);                //^^^^ add (better) 

stock:: required when defining function outside class.


Comments