Home > Back-end >  When doing C questions about class in the class of problems
When doing C questions about class in the class of problems

Time:09-24


Draw a circle as shown in figure, there is the Date I want to call that contains a constructor, but I don't know what to do, changed several times error, specific header file program is like this
 # # ifndef MENBER_H 
# define MENBER_H
# include & lt; string>
# include & lt; Iostream>

using namespace std;
The class Date
{
Int * year;
Int * month;
Int * day;
Public:
The Date (int len);//take arguments constructor is used to initialize the data members
To Date ();
Void Set_date (int);//type birthday information
Void Get_date (int);//output birthday information

};



The class Menber
{
Public:
Menber ();
Menber (int len);//take arguments constructor is used to initialize the data members
Virtual ~ Menber ();

int i;
The inline void header1 ();//build enter a header
The inline void header2 ();//build an output header
Void set_data (int);//type member information
Void show_data (int);//output member information
Void repete (int);//loop type
Void repete1 (int);//loop output
Private:
String * mem_name;
String * mem_sex;
Int * mem_num;
String * mem_identity;
The Date birth (int I);
};

Void Menber: : header1 ()
{
Cout<" Please enter the member information: \ n "& lt; <" Number \ t
"<" Name \ t "& lt; <" Gender \ t "& lt; <" Id \ t
"<" Birth year month day \ t "& lt; }

Void Menber: : header2 ()
{
Cout<" Member information as follows: \ n "& lt; <" Number \ t
"<" Name \ t "& lt; <" Gender \ t "& lt; <" Id \ t
"<" Birth year month day \ t "& lt; }

# endif//MENBER_H

CodePudding user response:

Not the Date the constructor code? After see the code to the len parameter is how to assign a value to the year, month, day?
You can try
Private:
.
The Date birth (20200405);//this parameter to try

CodePudding user response:

Should be no problem with your code, I am VS2015 c + + environment, put the code in main () function, CPP file the starting position of the place, not an error,

CodePudding user response:

Class Menber Date of birth (int I);  , which is a function declaration ah ~ ~ ~
You should write like this: the Date birth;
At the same time need to be initialized in the constructor:
Menber: : Menber (int len) : birth (len) {
//...
}
The default constructor for example:
Menber: : Menber () : birth (0) {
//...
}

CodePudding user response:

You write, the compiler should be considered a function declaration, then can't find the Date and the definition of the function body, don't know where you see this syntax, members of the class shouldn't initialize or assign a value to the constructor and the list of initialization function,,,

CodePudding user response:

Well, actually there I got a Date birth (int I) inside the "int I want to express" said there's a parameters of type int, want to invoke the oxygen content in the Date class constructors to initialize the members, is for everyone to see, that is, when I wrote the program is not so written (actually I don't know how to write, write error, before,,)

CodePudding user response:

reference 1st floor qybao response:
no Date constructor code? After see the code to the len parameter is how to assign a value to the year, month, day?
You can try
Private:
.
The Date birth (20200405);//this parameter try

I of the containing ginseng structure is like this:
Date: the Date (int len)
{
Year=new int [len];
The month=new int [len];
Day=new int [len];
}
Then I tried it on directly on the Date birth () directly using numerical Date in brackets bieth (10), but it's still an error,

CodePudding user response:

I don't think such the thing itself is very bad
  • Related