我有一个非常基础的类,无法访问它自己的成员。 我真的不明白为什么这不起作用。
头文件:
#ifndef SHAPE_1D_H
#define SHAPE_1D_H
#include "shape.h"
class Shape_1D : public Shape
{
public:
// Constructor for the class
Shape_1D();
};
#endif Shape_1D_H
.cpp 文件:
#include "shape.h"
// Constructor for the class
Shape::Shape(sf::VertexArray avVertices)
{
m_avVertices = avVertices;
}
// Draws the shape to the canvas
void draw(sf::RenderWindow window)
{
// ISSUE HERE - "Error: identifier "m_avVertices" is undefined"
window.draw(m_avVertices, sf::RenderStates::Default);
}
最佳答案
我看到您正在使用 SFML,所以我假设 Shape
最终继承了 sf::Drawable
。因此,您试图通过提供自己的(成员函数)来覆盖 Shape::draw
。
void draw(sf::RenderWindow window) {}
如果未在类定义本身中定义,则它不是成员函数定义。你忘了那里的东西。
关于c++ - 类方法无法访问 protected 成员 "Error: identifier is undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33444685/