简体   繁体   English

非法使用此类型作为表达式

[英]Illegal use of this type as an expression

class dataReader{
private:
    ifstream gfxDataFile;
    int numVertices;
    vector<*vertexData> vertices;
public:
    dataReader();
    dataReader(string file);
    ~dataReader();
    string getLine();
    int numberOfVertices();

};

the line with the vector gives me the error 向量行给我错误

vertexData: Illegal use of this type as an expression, any help guys? vertexData:非法使用此类型作为表达式,对您有帮助吗?

Heres the definition of vertexData 这是vertexData的定义

class vertexData{
private:
    float x;
    float y;
    float z;
public:
    vertexData();
    vertexData(float gx, float gy, float gz);
    ~vertexData();
    float getX();
    float getY();
    float getZ();
};

*vertexData should be vertexData* *vertexData应该是vertexData*

Putting the * on the left means, broadly, 'try to dereference the following expression' - and of course what follows is not a valid expression (though even if it were you'd have other problems trying to use an expression inside a template argument list...). 在左边加*的含义是,“尝试取消引用以下表达式”-当然,后面的表达式也不是有效的表达式(尽管即使您尝试在模板参数中使用表达式也遇到其他问题清单...)。 When declaring pointer types the * goes on the right of the type name. 声明指针类型时, *在类型名称的右侧。

Write * after the type: 在类型之后输入*

vector<*vertexData> vertices;  //wrong syntax
vector<vertexData*> vertices;  //correct syntax

As a sidenote, I don't think you need a vector of pointers. 作为附带说明,我认为您不需要指针向量。

Why don't you use this: 你为什么不使用这个:

vector<vertexData> vertices; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'LPVOID': 非法将此类型用作表达式 - 'LPVOID': illegal use of this type as an expression std :: string:非法使用此类型作为表达式 - std::string : Illegal use of this type as an expression 非法使用此类型作为表达式(错误)C++ - illegal use of this type as expression (error) C++ 简单的模板化函数可以转换std :: vectors-“非法使用此类型作为表达式” - Simple templated function to convert std::vectors - “illegal use of this type as an expression” “错误:C2275:&#39;QMouseEvent&#39;:非法使用此类型作为表达式” - “error: C2275: 'QMouseEvent' : illegal use of this type as an expression” 排序测试模板函数lambda:非法使用此类型作为表达式 - sort test templated function lambda: illegal use of this type as an expression 调用模板类成员时非法使用此类型作为表达式 - Illegal use of this type as an expression when calling template class member 错误:非法将此类型用作表达式。 C ++ - Error: illegal use of this type as an expression. C++ &#39;class&#39;:非法使用这种类型作为表达式我该如何解决? - 'class': illegal use of this type as an expression how do I fix it? 错误C2275 RHandle:非法使用此类型作为表达式 - error C2275 RHandle: illegal use of this type as an expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM