When encountering C problems, the default constructor initialization method is not familiar.

WBOY
Release: 2024-01-25 10:54:15
forward
647 people have browsed it

When encountering C problems, the default constructor initialization method is not familiar.

The C problem is specifically not initializing with the default constructor

The default constructor is the constructor without parameters

class Complex

{

private:

int real;

int image;

public:

void display();

Complex(){ //This is the default constructor with no parameters and is used to initialize C1

real=20;

image=40;

};

Complex(int x,int y):a(x),b(y){ //This is the constructor passed in parameters - an overload of the constructor is used to initialize C2

}

Complex(Complex &c) {//Another copy/copy constructor initialization C3

Real=c.Real;

Image=c.Image;

}

~Complex(){};

}

void display()

{

cout

}

void main(){

Complex c1();

Complex c2(0.0);

Complex c3(c1);

c1.display();

c2.display();

c3.display();

}

c No suitable default constructor is available

class CustomerData : public PersonData

{

private:

int customerNumber;

bool mailingList;

};

This class inherits PersonData, but the base class is not the default constructor, so you must explicitly declare the constructor in the inherited class and construct the base class object

class CustomerData : public PersonData

{

public:

CustomerData(string s,string f):PersonData(s,f){}

private:

int customerNumber;

bool mailingList;

};

The above is the detailed content of When encountering C problems, the default constructor initialization method is not familiar.. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!