我有一个类,它在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)
{
}
答案 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*
}