2013-05-25 5 views
-1

contructor 바로 앞에있는 함수를 포함하는 클래스가 있는데, 그 자체는 비어 있습니다. 그게 전부입니다. 따라서 클래스는 함수와 일부 중요하지 않은 요소를 포함합니다.클래스 내부에있는 함수 사용하기

내가 원할 때만 함수를 그 함수에서 호출 할 수 있습니까? ClassName ObjectName 그리고 ObjectName.FunctionName이 작동하지 않습니다.

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) :

헤더 파일의 내용이 클래스 (Cellstruct.h)에 속하는입니다
#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

괜찮습니다. 게시물을 업데이트 해 주셔서 감사합니다. – taocp

+0

함수를 어떻게 호출하고 오류를 표시 할 수 있습니까? – billz

+0

'ObjectName.FunctionName'은'FunctionName'이 클래스의 멤버 함수라는 것을 의미합니다. 그것이 아니라면, 당신은 단순히 이런 식으로 할 수 없습니다. – taocp

답변

1

ObjectName.FunctionNamevoid Automaton 기능을 언급하셨습니까?

그렇다면 Cellstruct 클래스의 일부로 보이지 않습니다. 소스 파일에서 다음

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

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

그리고 당신의 클래스의 일환으로 함수를 정의 :

클래스는 프로토 타입을 추가 헤더에서 void Automaton

에 대한 프로토 타입을 포함해야합니다.

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* 
} 
+0

그것은 작동합니다! 마침내 작동합니다. 고마워요! –