2013-06-05 2 views
1

MAIN.CPP :C++ 문제 - 정의되지 않은 참조

bool lgstatus; 
User currentUser; 
//... 
int main(){ //... } 

loginwindow.cpp : User 3 개 기능을 가지고

void LoginWindow::on_cmdCreate_clicked() 
{ 
    extern bool lgstatus; 
    extern User currentUser; 
    //... 
    currentUser.setMail(ui->txtAccountMail->text().toStdString()); 
    currentUser.setName(ui->txtAccountName->text().toStdString()); 
    currentUser.setPassword(ui->txtAccountPassword->text().toStdString()); 
    //... 
    lgstatus = true; 
} 

내 클래스입니다. 각각은 문자열을 인수로 사용합니다. 뭐가 잘못 됐는지 나는 모르겠다. lgstatus하지만 내 currenUser을 변경하면 컴파일러는 불평하지 않습니다.

등급 :

class User 
{ 
public: 
    User(); 
    User(const std::string &name, const std::string &password); 
    User(const std::string &name, const std::string &password, const std::string &mail); 

    void setName(const std::string &name); 
    void setMail(const std::string &mail); 
    void setPassword(const std::string &password); 

private: 
    std::string user_name; 
    std::string user_password; 
    std::string user_mail; 
}; 

내가뿐만 아니라 그들에게 보여 할 필요가있을 것이라고 생각하지 않는다 _ 이름 등에 "설정"기능을 단순히 통과 자신의 인수입니다.

오류 :

  • '사용자 : setMail (표준 : : 문자열 const를 &)'에 대한 정의되지 않은 참조

  • 사용자 ::에서는 setName (표준 : : 문자열 const를 & '에 대한 정의되지 않은 참조) '

  • 사용자 : SETPASSWORD (표준 : : 문자열 const를 &)`로 정의되지 않은 참조'

내가 뭘 잘못 했니?

+2

'User.cpp' (또는'User' 클래스의 구현을 포함하는 파일)과 다른 소스 파일을 컴파일하고 링크하고 있습니까? –

+1

'User' 클래스의 완전한 정의를 보여주기위한 include 파일이 있습니까? – unxnut

+0

정의를 사용자 클래스로 표시해야합니다. 간단한 set 메소드를 사용하면 인라인을 정의하고 메소드 선언 만 할 수 있습니다. –

답변

-1

loginwindow.cpp에서 올바른 #include를 수행하지 않은 것 같습니다. 따라서 컴파일러는 올바른 함수를 찾지 못합니다.