相关疑难解决方法(0)

为什么gcc会警告decltype(main())而不是clang?

请使用以下代码:

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++ gcc clang c++11

11
推荐指数
2
解决办法
485
查看次数

C++:朋友作为课堂上的主要人物

主要功能可以在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)

c++ constructor class friend

-3
推荐指数
1
解决办法
264
查看次数

标签 统计

c++ ×2

c++11 ×1

clang ×1

class ×1

constructor ×1

friend ×1

gcc ×1