VS 2013 错误积累(1)

Compiler Error C2440

  • conversion : 无法从 “type1”转换到“type2”
  • 编译器无法从“type1”强制转换到“type2”。


    • Compiler Error C2440
      • 使用 C 代码中的字符串来尝试初始化非常量 char
      • C2440 can also be caused if you attempt to convert a pointer to member to void
      • C2440 can also be caused if you attempt to cast from a type that is only forward declared but not defined


1. 使用 C++ 代码中的字符串来尝试初始化非常量 char*

int main() 
{
    char* s1 = "test"; // C2440
    const char* s2 = "tests"; // OK
}

2. C2440 can also be caused if you attempt to convert a pointer to member to void*.

3. C2440 can also be caused if you attempt to cast from a type that is only forward declared but not defined.

struct Base { }; // Defined

struct Derived; // Forward declaration, not defined

Base * func(Derived * d) 
{
    return static_cast<Base *>(d); 
    // error C2440:'static_cast' : cannot convert from 'Derived *' to 'Base *'
}

你可能感兴趣的:(error,c++基础)