没有检测到班级中的成员

时间:2013-08-26 13:51:35

标签: c++ gcc codeblocks

以下是Code :: Blocks

给出的EXACT错误
  

D:\ cpp \ AdventureTimeTest \ main.cpp | 12 |错误:'class adventure'没有   名为'drawMap'的成员

这是我的代码: -

在main.cpp

#include <iostream>
#include "adventure.h"

using namespace std;

int main()
{
    adventure a;

    a.setMapSize(10);
    a.drawMap();

    return 0;
}

在adventure.h中

class adventure
{
    public:
        adventure();
        virtual ~adventure();

        int mapSize;
        void setMapSize(int mapSize);
        int getMapSize();

        void drawMap();

    protected:
    private:
};

最后,在adventure.cpp中

#include <iostream>
#include "adventure.h"

using namespace std;

adventure::adventure()
{
}

adventure::~adventure()
{
}

void adventure::setMapSize(int par1)
{
    mapSize = par1;
}

int adventure::getMapSize()
{
    return mapSize;
}

void adventure::drawMap()
{
    for(int x = 0; x <= mapSize; x++)
    {
        for(int y = 0; y <= mapSize; y++)
        {
            cout << ". ";
        }
        cout << endl;
    }
}

谢谢,希望我能很快解决这个问题。

0 个答案:

没有答案