X类型的值不能用于初始化X类型的实体

时间:2018-07-16 06:38:06

标签: c++ visual-c++

struct Value {
    struct Array;
    struct Dict;
    struct Primitive;

    Value() {}
    virtual ~Value() {}

    virtual Array * asArray() { assert(false); }
    virtual Dict * asDict() { assert(false); }
    virtual Primitive * asPrimitive() { assert(false); }

    int asInt();
    double asDouble();
    std::string asDate();
    std::string asString();
};

struct Value::Array : public Value {
    std::vector<Value> m_data;

    Array() {}
    ~Array() {}

    Value::Array * asArray() { 
        Value::Array * result = this; 
        return result;
    }
};

语句Value::Array * result = this;给我这个错误...

E0144 a value of type "Value::Array *" cannot be used to initialize an entity of type "Value::Array *".

1 个答案:

答案 0 :(得分:0)

问题可以用更简单的代码看到

<input onclick="document.getElementById('codemenu').disabled = false;
document.getElementById('codecustom').disabled = true;" type="radio"
name="codebutton" value=""  checked="checked">

<select name="exp_code" id="codemenu">
<option value="MATS">MATS</option>
<option value="WAGES">WAGES</option>
<option value="FUEL">FUEL</option>
<option value="AD">AD</option>
<option value="TAX">TAX</option>
<option value="GAS">GAS</option>
<option value="OH">OH</option>
</select>
<p>
<input onclick="document.getElementById('codecustom').disabled = false;
document.getElementById('codemenu').disabled = true;" type="radio"
name="codebutton">

<input type="text" name="exp_code" id="codecustom" placeholder="Custom Code" 
disabled="disabled"
autocomplete="on">

enum SPELLSTATUS { NEW, FAIL, OK } spellStatus = SPELLSTATUS::NEW;

编译并运行正常。