Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Constructor-problem

Status
Not open for further replies.

Irisbe

Programmer
Jul 20, 2004
1
BE
I'm having trouble with a constructor in my class and can't figure out what the problem might be. The default constructor works fine, but the one where is given a const reference to a string as argument keeps resulting in the following error:

configparser.C: In constructor `ConfigParser::ConfigParser(const std::string&)':
configparser.C:25: error: no match for call to `(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >) ()'
make: *** [configparser.o] Fout 1

I have no idea what's causing this. If someone could help me out -> I would be very grateful.

Code:
using namespace std;

class ConfigParser {
        public:
                ConfigParser() throw (runtime_error);
                ConfigParser(const string& configfile) throw (runtime_error);
                ~ConfigParser();
                const int port() const {return port_;}
                const string& logfile() const {return logfile_;}
                const string& docroot() const {return docroot_;}
                const string& typesfile() const {return typesfile_;}
                const string& configfile() const {return configfile_;}
	private:
                int port_;
                string logfile_;
                string docroot_;
                string typesfile_;
                string configfile_;
};

Constructor funtion (doesn't do much @the moment, just returning the path-string):

Code:
ConfigParser::ConfigParser(const string& configfile) throw (runtime_error): configfile_(configfile){
        cout << configfile();
}
 
1. Why << configfile(), not configfile w/o parenthesis?
2. This snippet was compiled (then linked after some obvious stubs added) OK with VC++ 6.0 SP5 (w/o throw specs) and with Dev-C++ V.4.9.8.7 (exactly as posted w/o configfile())...
May be it's your compiler version issue?..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top