使用类中的函数

时间:2013-05-25 23:51:58

标签: c++ class function call

我有一个类,它在contstructor之前包含一个函数,它本身就是空的,就是这样,所以我的类只包含函数而一些不是那么重要的元素。

如何通过该功能调用该功能,但仅限于我需要的时候? ClassName ObjectName然后ObjectName.FunctionName不起作用。

这是头文件的内容属于类(Cellstruct.h):

typedef struct tiles
{
    unsigned char red, green, blue;
}tiles;

const tiles BASE = {0,0,0};
const tiles TEST_ALIVE = {255,0,0};
const tiles CONWAY_ALIVE = {0,255,0};
const tiles CONWAY_DEAD = {0,50,0};

class Cellstruct
{
public:
    Cellstruct(void);
    virtual ~Cellstruct(void);
};

这是cpp文件的内容属于类(Cellstruct.cpp):

#include "Cellstruct.h"

bool equality(tiles* a, const tiles* b) 
{
    if (a->red == b->red && a->green == b->green && a->blue == b->blue)
    {
        return true;
    } else {
        return false;
    }
}

void Automaton(tiles arra[fullwidth][fullheight], tiles arrb[fullwidth][fullheight])
{

//*this is way too long so I cut it, I think it doesn't really matter*

}

Cellstruct::Cellstruct(void)
{
}

Cellstruct::~Cellstruct(void)
{
}

1 个答案:

答案 0 :(得分:1)

ObjectName.FunctionName是指您的void Automaton功能?

如果是这样,它似乎不是您的Cellstruct类的一部分。

您的课程应包含void Automaton

的原型

在标题中,添加原型:

class Cellstruct
{
public:
    Cellstruct(void);
    virtual ~Cellstruct(void);

    void Automaton(tiles arra[fullwidth][fullheight], tiles arrb[fullwidth][fullheight]); //Add this
};

然后在源文件中,将函数定义为类的一部分。

void Cellstruct::Automaton(tiles arra[fullwidth][fullheight], tiles arrb[fullwidth][fullheight])
{
    //*this is way too long so I cut it, I think it doesn't really matter*
}