dafault constructor
Aug 30, 2012 at 8:35am UTC
hi evryone! I get the this error:
error C2512: 'Temp_client' : no appropriate default constructor available
what i should do to solve the problem? thanks...
#ifndef SILVER_H
#define SILVER_H
#include<string>
#include<cstring>
#include<map>
#include<iostream>
#include<sstream>
#include<stdlib.h>
using namespace std;
silver.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class Temp_client{
public : Temp_client(string temp_phone_number,string temp_Company_name);//CONSTRUCTOR
~Temp_client(){};//DESTRUCTOR
string Phone_number;
string Company_name;
double Must_pay;
int Minute_counter;
};
class Maps:Temp_client{
public : Maps(string temp_Phone_number,string full_name[]);//costructor
void PrintReport() const ;
~Maps(){};
private :map<string,Temp_client> index;
};
#endif
silver.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
#include "silver.h"
Temp_client::Temp_client(string temp_phone_number,string temp_Company_name)
{
Phone_number=temp_phone_number;
Company_name=temp_Company_name;
Must_pay=0;
Minute_counter=0;
};
Maps::Maps(string temp_Phone_number,string full_name[])//,string full_name[],string Id_number[],string Company_name[],string rank_number
{
if (full_name==NULL)
{
Temp_client T1(temp_Phone_number,"CELLCOM" );
Maps::index.insert(make_pair(temp_Phone_number,T1));
map<string,Temp_client>::const_iterator it;
for (it=index.begin() ;it!=index.end() ;it++)
cout<<it->second.Phone_number;
}
};
Last edited on Aug 30, 2012 at 8:40am UTC
Aug 30, 2012 at 9:20am UTC
You declared class Maps as a derived class of class Temp_client.
class Maps:Temp_client
So during construction of an object of type Maps a constructor of base class Temp_client shall be called. As you did not explicitly specify which constructor of Temp_client will be called the compiler tries to call the default constructor of this class, that is Temp_client() . However you did not defined the default constructor of class Temp_client.
Aug 30, 2012 at 9:34am UTC
'Temp_client' does not have a default constructor so u have to initialize that member in your 'Maps' class's default constructor...
Topic archived. No new replies allowed.