I get error "no instance of constructor".

I get error with constructor. I don't know what is wrong.
Date is the base class for all the hierarchy

1
2
3
This is constructor for Seniour worker 

SeniourWorker(string &, string &, string &, int = 0, int = 0, int = 0,int=0);


1
2
3
4
JuniourWorker inherits from SeniourWorker and has the same constructor

JuniourWorker::JuniourWorker(string &first, string &last, string &ssn, int d, int m, int y, int b)
	:SeniourWorker(first,last,ssn,d,m,y,b)


This is where i get the error in main
1
2
3
4
vector <Date*> bus(2);	//polymorphic bus

bus.at(0) = new JuniourWorker("Kouatcha","Calson","FE13400",3,4,1994,6);
bus.at(1) = new SeniourWorker("Acha","Bill","FE13A041",4,9,1993,9);


Visual Studio tells me my string arguments for JuniourWorker and SeniourWorker are const char * .
Is this the reason for the contrast with string & in the deceleration?

If this is the reason, how do i input string arguments in the initialization of the constructors without explicitly declaring string variables for them?
You cannot bind a constant or temporary to a non-const reference.
(Because you cannot modify a constant)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <string>

void foo (std::string&) { }
void foo (const size_t&) { }
int  bar () { return 1; }

int main()
{
    //int& i = 25; // nope
    //int& j = bar(); // nope
    const int& j = bar(); // valid
    //foo ("John"); // nope
    foo (100u); // valid
}


Therefore you need to make your string parameters in your constructor const
Last edited on
Thanks 'troll warlod' it worked.
Topic archived. No new replies allowed.