C++ 类方法可以';t访问受保护的成员“;错误:标识符未定义";

C++ 类方法可以';t访问受保护的成员“;错误:标识符未定义";,c++,visual-c++,C++,Visual C++,我有一个非常基本的类,无法访问它自己的成员。 我真的不明白为什么这样不行 头文件: #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 #include "shape.h" // Constructor fo

我有一个非常基本的类,无法访问它自己的成员。 我真的不明白为什么这样不行

头文件:

#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
#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);
}
.cpp文件:

#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
#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窗口){}
如果不是在类定义本身中定义的,则它不是成员函数定义。你忘了一些东西。

我知道你在使用SFML,所以我假设
Shape
最终继承了
sf::Drawable
。因此,您试图通过提供自己的(成员函数)来覆盖
Shape::draw


void draw(sf::RenderWindow窗口){}
如果不是在类定义本身中定义的,则它不是成员函数定义。你忘了那里的东西。

你可能只是忘了
形状:
绘图
前面,如果它应该是一个成员函数:

void Shape::draw(sf::RenderWindow window) {
     ^^^^^^^

您可能只是忘记了
Shape::
draw
前面,如果它应该是一个成员函数:

void Shape::draw(sf::RenderWindow window) {
     ^^^^^^^