#include <iostream>
using namespace std;
class DrivingLicence
{
protected:
Person owner;
char * type;
Date validity;
int id;
static int cid;
public:
DrivingLicence(Person &o,char* t,Date &d);
DrivingLicence(Person &o,char* t);
DrivingLicence(const DrivingLicence & other);
Date getValidity() const;
int checkValidity() const;
void print() const;
bool operator== (const DrivingLicence& o) const;
void operator +(const int num);
const DrivingLicence& operator= (const DrivingLicence& other);
~DrivingLicence();
};
class Person
{
private:
int id;
char* name;
Date birthday;
public:
Person(char* name,int id1,Date &d);
Person(const Person &other);
~Person();
Date getBirthday() const;
const Person& operator= (const Person & other);
void print() const;
};
class Date
{
int day;
int month;
int year;
public:
Date (int day,int month,int year);
~Date();
const Date& operator=(const Date& other);
bool operator==(const Date & other);
void print() const;
int getYear()const;
int getMonth()const;
int getDay()const;
};
了以上是我的班,我 需要在DrivingLicence
类(而不是复制利弊)来初始化构造函数,但我不能设法做到这一点。初始化构造函数C++
有人可以帮助我解决这个问题的语法吗?
我的意思是:
#include <NameOfHeaderFile>
DrivingLicense::DrivingLicense(Person &o,char* t,Date &d) : //Code here for 1stconstructor
{
}
DrivingLicense::DrivingLicense(Person &o,char* t) ://Code here for 2nd constructor
{
}
我不知道如何初始化值
试试看吧?对我而言,你完全不清楚你有什么问题。 – nvoigt 2014-10-08 12:09:09
初始化一个构造函数?你不初始化构造函数......构造函数初始化类的实例(或者至少它们应该这样做)。 – luk32 2014-10-08 12:11:59
你为什么在C++中使用char *'?如果这是一个字符串,请使用'std :: string'。 – crashmstr 2014-10-08 12:16:06