小编The*_* do的帖子

无效的整型常量表达式

在这段代码中:

// CompileTimeWarnings.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <type_traits>
using namespace std;
#define __STR1__(x) #x

#define __LOC__ __FILE__ "("__STR1__(__LINE__)") : warning : "

// collisions.cpp

template<class T, class T1>
struct mismatch
{
    //enum {value = is_signed<T>::value && is_signed<T1>::value};
    static const bool value; //= is_signed<T>::value && is_signed<T1>::value;
};

template<class T, class T1>
bool mismatch<T,T1>::value = is_signed<T>::value && is_signed<T1>::value;

template<class T>
struct Int
{
};

template<class T, class T1>
int operator+(Int<T> t, Int<T1> t1) …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2010

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

无法在GCC中为IntType定义MAX值

为什么这在GCC 4.5.1中不起作用

#include <iostream>  
#include <type_traits>
#include <limits.h>//for INT_MIN
#include <typeinfo>
using namespace std;

#ifdef _MSC_VER
#define UNIVERSAL_INT_MAX LLONG_MAX
#define UNIVERSAL_INT_MIN LLONG_MIN
#endif

#ifdef __GNUC__
#define UNIVERSAL_INT_MAX LONG_LONG_MAX  
#define UNIVERSAL_INT_MIN LONG_LONG_MIN
#endif
using namespace std;

int main()
{
    cout << UNIVERSAL_INT_MAX << '\n';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

"main.cpp|24|error: 'LONG_LONG_MAX' was not declared in this scope"  
Run Code Online (Sandbox Code Playgroud)

编辑

#ifdef __GNUC__
#define UNIVERSAL_INT_MAX ( ( 1ULL << numeric_limits< long long >::digits ) - 1 )
#define UNIVERSAL_INT_MAX_plus_three (UNIVERSAL_INT_MAX + 3)
#endif
using namespace …
Run Code Online (Sandbox Code Playgroud)

c++ gcc

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

如何生成编译时错误?

我希望能够做到这样的事情:

   void f(int*p = nullptr)
    {
    if (!p)
{
//HERE I WOULD LIKE TO HAVE AN MSG THAT WOULD BE DISPLAYED DURING COMPILATION AS A WARNING POSSIBLY
}
    }
Run Code Online (Sandbox Code Playgroud)

c++

-2
推荐指数
3
解决办法
3602
查看次数

它为什么有效?SFINAE

template<class T, class U>
struct is_convertible
{
    typedef char yes;
    typedef struct
    {char _[2];}no;

    static yes test(U);
    static no test(...);
    enum {value = (sizeof(test(0)) == sizeof(yes)) ? 1 : 0};
//THE PART I'M INTERESTED IN IS (test(0)). Why 0 (zero) works here?

};
Run Code Online (Sandbox Code Playgroud)

请在代码中查看评论.

c++ sfinae

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

为什么功能失重?

为什么在我的班级有功能不会改变这个班级的大小?这些信息必须存储在某个地方,但在哪里?

c++

-4
推荐指数
1
解决办法
269
查看次数

static_assert 中的 decltype

为什么类定义中的 this (static_assert) 不起作用?

template<class IntT, IntT low = IntT(), IntT high = IntT()>
struct X 
{
    static_assert(std::is_same<decltype(low),decltype(high)>::value,"Different types not allowed");
};



int _tmain(int argc, _TCHAR* argv[])
{
    int low, high;

    X<char,1,'a'> x;//HERE I SHOULD GET ERROR
    cout << sizeof(x);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ static-assert decltype c++11

-8
推荐指数
1
解决办法
2357
查看次数

标签 统计

c++ ×6

c++11 ×1

decltype ×1

gcc ×1

sfinae ×1

static-assert ×1

visual-studio-2010 ×1