| |

VerySource

 Forgot password?
 Register
Search
Author: afeng009

Please master teach how to new a class

[Copy link]

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-12 13:45:01
| Show all posts
//The call of the constructor is the same as the ordinary function. If you don’t even know ordinary functions, go back and read a book first.
CActiveProcess* p = new CActiveProcess("name1","sname2","sname3","sname4",
                                       "sname5","sname6","rname1","rname2","rname3", "help",&ture)
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2021-3-12 14:00:01
| Show all posts
I have never seen such a long parameter. I have read it all, and dropped two commas.

CActiveProcess *activeProcess =
new
CActiveProcess(
param1,param1,param1,
param1,param1,param1,param1,
param1,param1,param1,param2,
param2 ,param3 );
Reply

Use magic Report

1

Threads

13

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2021-3-12 14:15:01
| Show all posts
CActiveProcess* one = new CActiveProcess;
Will this be wrong? If it’s really wrong... (don’t understand)

According to the definition in the book:
Type name * pointer variable name = new type name (if there is a constructor with parameters, assign initial values ​​to the parameters)
//If it is not in (), do not write, the compiler will automatically call the default constructor


new CActiveProcess(char *sname1,char *sname2,char *sname3,
char *sname4,char *sname5,char *sname6,char *rname1,
char *rname2,char *rname3,char*help,float*ture, float*error,__int32 *finger);

//Of course it’s not possible to write this way, because variables like *sname2 are waiting for us to assign values, so let me change it casually:
//CActiveProcess* one=new CActiveProcess(a,b,c,d,e,f,g,h,i,help,ture, false,1);
//Probably that's it
Reply

Use magic Report

2

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2021-3-12 14:30:01
| Show all posts
Thank you, everyone. I am almost a beginner, and I am now in the practice stage, which makes everyone laugh. There is still a lot to learn, thank you again for your enthusiasm.
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2021-3-12 15:15:01
| Show all posts
Beginners wrote very amazing constructors, very clever.

If there are many parameters passed, it is better to design a structure to encapsulate it, which is cleaner.
Reply

Use magic Report

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-12 15:30:01
| Show all posts
gosh. . . This is obviously a class library of mfc or vcl. . . . .
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2021-3-12 15:45:01
| Show all posts
If MFC is designed in this way, it should not be in line with Microsoft's style.
As soon as there are more parameters, he will come up with n more structures

VCL should not appear, after all, it was written by Delphi

More parameters are better encapsulated into classes or structure
Reply

Use magic Report

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-12 16:00:01
| Show all posts
The content contained in the name CActiveProcess will not be written by people at the level of lz. Besides, if lz can write such a constructor. If you don't call it, it's even more incredible. .
Reply

Use magic Report

2

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2021-3-12 16:15:01
| Show all posts
Thank you very muchdiamond52; for telling me the truth, it seems that the basics are too unreliable. Go back and read the book carefully, thank you!
Reply

Use magic Report

2

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2021-3-12 16:30:01
| Show all posts
Thank you for your enthusiasm. I hope you can get your advice next time if you have any questions.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list