加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – ‘使用函数’是什么意思

发布时间:2020-12-16 09:29:31 所属栏目:百科 来源:网络整理
导读:$3.6.1 / 3州 – “The function main shall not be used (3.2) within a program.”. 下面以学术为动机的示例程序使用了我认为合法的几种方式的名称“main”.这是基于“函数的使用”与调用函数(直接/间接)相关的假设. struct MyClass{ private: MyClass(){}
$3.6.1 / 3州 –

“The function main shall not be used
(3.2) within a program.”.

下面以学术为动机的示例程序使用了我认为合法的几种方式的名称“main”.这是基于“函数的使用”与调用函数(直接/间接)相关的假设.

struct MyClass{ 
private: 
   MyClass(){}  
   friend int main(); 
};   

int main(){  
   MyClass m;  
   int (*p)() = main; // but don't do anything 
}

>足够公平,显示的代码用gcc / VS 2010编译.
>我对Comeau的错误感到惊讶.

Comeau online在声明’p’时出错(即在接收’main’的地址时),但在声明’main’为朋友时却没有.

谁/什么是关于C 03的权利?

解决方法

C03§3.2/ 2说:

An object or non-overloaded function is used if its name appears in a potentially-evaluated expression.

它继续列出了构成其他各类实体的使用的内容;这是重要的一个.

朋友声明不是表达.

当函数main()被转换为指针并且该指针被赋值给p时,这是一个表达式并且可能被评估(C03§3.2/ 2):

An expression is potentially evaluated unless it appears where an integral constant expression is required (see 5.19),is the operand of the sizeof operator (5.3.3),or is the operand of the typeid operator and the expression does not designate an lvalue of polymorphic class type (5.2.8).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读