当前位置:网站首页>Colon function and explicit keyword in constructor
Colon function and explicit keyword in constructor
2022-04-23 21:57:00 【Three stone orders】
The colon in the constructor functions , Class assigns values to member variables , Constants that are more suitable for member variables const type .
class myClass
{
/* The colon in the constructor functions , Class assigns values to member variables , Constants that are more suitable for member variables const type .*/
public :
myClass();// Constructors , No return type , You can have a list of parameters , There is no need for
~myClass();// Destructor
int a;
const int b;
}
myClass::myClass():a(1),b(1)// Initialization list
{
}
myClass::myClass()
{
a = 1;// you 're right , The effect is equivalent to initializing in the initialization list
b = 1;// error ,const Variables cannot be assigned ;
}
Constructor with explicit keyword , Disable implicit conversion , That is, when calling this class, you must declare that it is a class ; Without this keyword, you can directly assign the data type value in the constructor
class AAA
{
public:
//AAA(int a) : num(a) {}
explicit AAA(int a) : num(a) {
}
int GetValue() {
return num; }
private:
int num;
};
int fun(AAA aaa)
{
return (int)aaa.GetValue() + 1;
}
int main()
{
//int a = fun(5);
int a = fun(AAA(5));
}
版权声明
本文为[Three stone orders]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204200615437072.html
边栏推荐
- [leetcode refers to the substructure of offer 26. Tree (medium)]
- 在线时序流程图制作工具
- Keras. Layers introduction to various layers
- Detailed explanation of basic assembly instructions of x86 architecture
- Resolve the "chromedriver executable needs to be in path" error
- Display, move, rotate
- [leetcode refers to offer 47. Maximum value of gift (medium)]
- 1. Finishing huazi Mianjing -- 1
- Tencent cloud has two sides in an hour, which is almost as terrible as one side..
- Tear the Google SRE book by hand
猜你喜欢

Database Experiment 2 data query

Online Excel to CSV tool

Opencv application -- jigsaw puzzle
![[leetcode refers to offer 47. Maximum value of gift (medium)]](/img/b4/34b3c74516e3b1ba93b7d84916dadc.png)
[leetcode refers to offer 47. Maximum value of gift (medium)]
![[leetcode refers to offer 52. The first common node of two linked lists (simple)]](/img/bc/cd9c6ec29ecfef74940200e196aed3.png)
[leetcode refers to offer 52. The first common node of two linked lists (simple)]
![[leetcode sword finger offer 28. Symmetric binary tree (simple)]](/img/bc/1f0c9e70470c7d60f821a4ecc2271f.png)
[leetcode sword finger offer 28. Symmetric binary tree (simple)]

Minecraft 1.12.2 module development (43) custom shield

Deep understanding of modern mobile GPU (continuously updating)

How to make Jenkins job run automatically after startup

C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
随机推荐
[leetcode refers to the two numbers of offer 57. And S (simple)]
Pycharm Chinese plug-in
opencv应用——以图拼图
[leetcode refers to offer 32 - III. print binary tree III from top to bottom (medium)]
【SDU Chart Team - Core】SVG属性类设计之枚举
Tensorflow realizes gradient accumulation, and then returns
Thinkphp5 + data large screen display effect
[leetcode refers to the maximum profit of offer 63. Stock (medium)]
Based on jsplumb JS to achieve multi list one to many connection effect
How to play the guiding role of testing strategy
[leetcode refers to offer 25. Merge two sorted linked lists (simple)]
Question brushing plan -- backtracking method (I)
Sharpness difference (SD) calculation method of image reconstruction and generation domain index
Database experiment I database definition and data import
Pipes and xargs
2022-04-24日报:在生物科学领域应用深度学习的当前进展和开放挑战
MySQL back to table
[leetcode refers to offer 22. The penultimate node in the linked list (simple)]
Presto on spark supports 3.1.3 records
引入结构化并发,Swift 5.5 发布!