c++ - 类方法无法访问 protected 成员 "Error: identifier is undefined"

标签 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

.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/

相关文章:

c++ - std::promise 是否在内部使用 std::condition_variable 来通知关联的 std::future?

visual-c++ - 使用 #pragma Once 或 #ifndef#endif 哪个更有效?

windows - 我如何在 Windows 中为类似/dev/null 的东西调用 CreateFile?

c++ - 我想通过递归获得列表元素的每个排列

c++ - 我的文件依赖性有什么问题?

c++ - 关于 C++ 异常处理

c++ - 对话框背景和单选按钮透明度

c++ - IMediaControl::stop 在没有信号时挂起

c++ - 如何使用 BSD 套接字查找 ip 地址?

c++ - 我应该在我的 C++ 程序中混合使用 C 和 C++ 风格的 I/O 吗?