2015-01-25 2 views
-1

나는 casilla.cpp와 casilla.h의 두 클래스를가집니다.변수 재정의 오류

cpp 하나에서 클래스 재정의 오류가 발생하고 .h "클래스 casilla에 대한 이전 정의가 있습니다. 인터넷에서 검색했지만 casilla를 배치하지 않았습니다. 헤더가 작동 퍼팅 여기에 코드입니다 :.

Casilla.h :

#ifndef CASILLA_H_ 
#define CASILLA_H_ 


using namespace std; 

class Casilla { //previous definition of ‘class Casilla’ 
public: 
casilla(); //ISO C++ forbids declaration of ‘casilla’ with no type [-fpermissive] 
virtual ~casilla(); //expected class-name before ‘(’ token 

void SetNumeroCasilla (int _numero); 
}; 

/* namespace std */ 

#endif /* CASILLA_H_ */ 

Casilla.cpp :.

#include "Casilla.h" 
    #include "Tablero.h" 
    using namespace std; 


#include <iostream> 
#include <iomanip> 
class Casilla //errors :Multiple markers at this line 
- redefinition of ‘class Casilla’ 
- Line breakpoint: Casilla.cpp [line: 
17] 
{ 
int fila; 
int columna; 
int numero; 

public: 

    // default constructor 
Casilla::Casilla() 
: fila(-1) 
, columna(-1) 
, numero(0) 
{ } 

int GetNumero() {return numero;} 
void SetCasillaPosition (int _fila, int _columna) //set a cell position 
    { 
     fila = _fila; 
     columna = _columna; 
    } 
void SetNumeroCasilla (int _numero)    //set a cell value 
    { 
     numero = _numero; 
    } 
void SetCasillaFull (int _fila, int _columna, int _numero) //set a cell  position and value 
    { 
     fila = _fila; 
     columna = _columna; 
     numero = _numero; 
    } 

}; 

그냥 새로운 오류가있는 코드를 변경 표시가 redef ined 오류가 계속 발생하면 무엇을 잘못 했습니까?

답변

3

casilla.cpp에서 casilla ...을 다시 정의하고 있습니다. class casilla { .. };은 클래스 정의이며, 두 번 : 헤더와 cpp에 두 번 있습니다. 따라서 재정의 오류가 발생합니다. 그것은 몇 가지 오류를 표시

#include "Casilla.h" 
// other includes 

// define the default constructor: 
casilla::casilla() 
: fila(-1) 
, columna(-1) 
, numero(0) 
{ } 

// define this function 
void casilla::SetNumeroCasilla (int _numero) 
{ 
    // something 
} 
+0

내가했지만 : 나는 새로운 코드로 영업을 편집

당신은 통화 당에서해야 할 일은

당신이 당신의 .h에 선언 된 클래스 메소드에 대한 정의를 제공하는 것입니다 나타나는 각 줄의 오류 – flaixman

+0

@flaixman 당신은 여전히 ​​당신의 cpp에'class Casilla'를 가지고 있습니다. 내 대답은 그렇지 않습니다. – Barry

+0

고마워, 방금 맞았 어. 당신의 도움을 주셔서 감사합니다. – flaixman