no matching constructor for initialization
Apr 14, 2014 at 6:39pm UTC
Hi, i am writing my first C++ in pop syle, so please go easy on me, but i get an error when compelling this code below: no matching constructor for initialisation of 'customer':
customerDetails.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#ifndef __BankAccount_Program__CustomerDetails__
#define __BankAccount_Program__CustomerDetails__
#include <string>
using namespace std;
class customer{
private :
string name;
string address;
string city;
string county;
string postcode;
int phoneno;
public :
customer (string name, string address, string city, string county, string postcode, int phoneno);
string getName() const ;
string getAddress() const ;
string getCity() const ;
string getCounty() const ;
string getPostcode() const ;
int getNumber() const ;
void print() const ;
};
#endif
customerDeails.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <iostream>
#include "CustomerDetails.h"
using namespace std;
customer::customer(string name, string address, string city, string county, string postcode, int phoneno){
this ->name = name;
this ->address = address;
this ->city = city;
this ->county = county;
this ->postcode = postcode;
this ->phoneno = phoneno;
}
string customer::getName()const {
return name;
}
string customer::getAddress() const {
return address;
}
string customer::getCity() const {
return city;
}
string customer::getCounty() const {
return county;
}
string customer::getPostcode() const {
return postcode;
}
int customer::getNumber() const {
return phoneno;
}
void customer::print() const {
cout<<name<<endl;
cout<<address<<endl;
cout<<city <<endl;
cout<<county <<endl;
cout<<postcode <<endl;
cout<<phoneno<<endl;
}
run.cpp (File i am executing)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "CustomerDetails.h"
using namespace std;
//void banner();
int main()
{
customer daniel("Daniel Bramley" , "30 Angel Road" , "Basingstoke" , "Hampshire" , "RG22 4NY" , "01245678485" );
daniel.print();
customer james("1" , "2" , "3" ,"4" ,"5" ,"6" );
james.print();
return 0;
}
Its in the run.cpp that i get the error.
Thanks for any help
Michael
Apr 14, 2014 at 7:03pm UTC
1 2
customer daniel("Daniel Bramley" , "30 Angel Road" , "Basingstoke" , "Hampshire" , "RG22 4NY" ,
"01245678485" );
customer(string, string, string, string, string, int );
Compilation is unsuccessful because you've given arguments of types that are not implicitly convertable to integers or integer themselves. Simply pass a value of a satisfactory type or modify the declaration and definition of the constructor to solve this issue.
Apr 14, 2014 at 7:10pm UTC
Ok awesome, that makes sense. Thanks very much
Topic archived. No new replies allowed.