c++写文件到本地工具类_什么是C ++中的本地类?

c++写文件到本地工具类

Classes that are defined and used inside a function or a block are known as local classes. Lets take an example.

void demo(int x) //enclosing function
{
…..
…..
class test  //local class
{
…..
….. //definition
};


…..
…..


test t(x); //creating object
….. //use test object
}

Also Read: What is Slack Byte in Structure?
Also Read: What is Virtual Base Class in C++?

In above example test class is a local class that is defined inside function demo(). It is a C++ concept that is explained in few books and is rarely used. 

There are few restrictions with local classes that must be taken in care.

1. Local class can use global variables (declared above the function) and static variables declared inside the function but cannot use automatic local variables.
2. The global variables should be used with the help of scope resolution operator (::).
3. They cannot have static data members and member functions must be defined inside the local classes.
4. Enclosing function cannot access the private members of a local class. This can be done by declaring the enclosing function as a friend function.

I have shared a video below that will help you to understand the concept of local class easily.

There may be few things that I have missed in above article, mention it by commenting below. If you liked the above tutorial then do share with others!!

翻译自: https://www.thecrazyprogrammer.com/2013/12/what-are-local-classes-in-c.html

c++写文件到本地工具类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值