请使用以下代码:
int main()
{
decltype(main()) x = 0;
return x;
}
Run Code Online (Sandbox Code Playgroud)
gcc抱怨:
main.cpp: In function 'int main()':
main.cpp:8:19: warning: ISO C++ forbids taking address of function '::main' [-Wpedantic]
decltype(main()) x = 0;
^
main.cpp:8:19: warning: ISO C++ forbids taking address of function '::main' [-Wpedantic]
Run Code Online (Sandbox Code Playgroud)
但没有铿锵 那么怎么decltype(main())会引发这个错误呢?怎么decltype拿主要的地址?
主要功能可以在C++中成为好友功能吗?
#include "stdafx.h"
#include <iostream>
using namespace std;
class A {
public:
A():i(10){}
private:
int i;
friend int main();
};
int main()
{
A obj;
cout<<obj.i;
return 0;
}
Run Code Online (Sandbox Code Playgroud)