2013-03-05 3 views
1

프로젝트를 Xcode로 이동하기 시작했으며 프로젝트를 빌드 할 때 생성자 정의에 오류가 발생합니다. 기본 생성자에서 "예상 구성원 이름 또는 ';" 선언 지정자 후 "다른 생성자에 내가 얻을 :C++ Xcode 생성자 오류

  1. "예상 ')' "
  2. 이 필드를 불완전 형 '버튼 : 버튼'
  3. 비 친구 - 클래스 멤버 '문자열'을 가지고 할 수 없습니다 이름


#include <string> 

#ifndef BUTTON_H 
#define BUTTON_H 

namespace interface1 
{ 
class Button 
{ 
    private: 
     std::string name; 
     float xPos; 
     float yPos; 
     float width; 
     float height; 

    public: 
     //Default constructor 
     Button::Button(); 
     //Constructor with id, x, y, width and height parameters 
     Button::Button(std::string, float, float, float, float); 

     //Getters and setters 
     std::string getName(); 
     float getX(); 
     void setX(float); 
     float getY(); 
     void setY(float); 
     float getWidth(); 
     void setWidth(float); 
     float getHeight(); 
     void setHeight(float); 
     bool isClicked(int, int); 
     void draw(int, float, float, float, float); 
}; 
} 
#endif 

어떤 생각을 자격이 무엇인지 잘못 됐어?

+7

'Button ::'을 제거하십시오. – chris

+0

감사합니다. 어떻게하면 Visual Studio에서 필요하지만 xCode에서는 필요하지 않습니까? – user1356791

+5

당신은 VS에서 그것도 필요하지 않습니다 – badgerr

답변

2

생성자가 클래스 정의 내부에 있으므로 다른 멤버 함수와 마찬가지로 접두사는 Button::이 필요하지 않습니다. 일부 컴파일러는 여전히 추가 자격을 수락하고 일부는 그렇지 않습니다.

class Button { 
    Button(); //already in class scope, so no extra qualification needed 
}; 

한편, 이러한 멤버를 클래스 외부에서 정의하면 자격이 필요합니다. 그렇지 않으면 새로운 함수를 만듭니다 (적어도 리턴 타입을 가진 비 생성자의 경우) :