2013-05-08 3 views
5

헤더 파일과 호환되지선언 형식

#include "bankAccount.h" 
#include <string> 
#include <iostream> 
using std::string; 


string bankAccount::getAcctOwnersName() const 
{ 
    return acctOwnersName; 
} 
int bankAccount::getAcctNum() const 
{ 
    return acctNum; 
} 
double bankAccount::getBalance() const 
{ 
    return acctBalance; 
} 
void bankAccount::setAcctOwnersName(string name) 
{ 
    acctOwnersName=name; 
} 
void bankAccount::setAcctNum(int num) 
{ 
    acctNum=num; 
} 
void bankAccount::setBalance(double b) 
{ 
    acctBalance=b; 
} 
void bankAccount::print() const 
{ 
    std::cout << "Name on Account: " << getAcctOwnersName() << std::endl; 
    std::cout << "Account Id: " << getAcctNum() << std::endl; 
    std::cout << "Balance: " << getBalance() << std::endl; 
} 

내가 getAcctOwnersName에서 오류를 얻을 수 있도록하고, setAcctOwnersName이 선언은 "< 오류 -와 호환되지 않는 것을 주장하십시오 type> bankAccount :: getAcctOwnersName() const "를 입력하십시오.

+1

헤더 파일에 ''이 (가) 포함되어 있지 않으므로 코드가 컴파일되어서는 안됩니다. 문제는 헤더가'std :: string'와는 다른'string '의 의미를 가질 것이라고 생각합니다. '#include '을 헤더에 넣고 거기에 일반'string' 대신'std :: string'을 사용하십시오. 도움이되는지 확인하십시오. – Angew

+2

컴파일러가 표시하는 * 첫 번째 오류가 아니라면 무시하는 것이 가장 좋습니다. 오류 목록을 항상 위에서 아래로 살펴보십시오. 마지막으로 인쇄 할 때 시작하지 마십시오. 출력에서 ​​찾을 수있는 것이 가장 쉽습니다. 종종 프로그램의 한 실수는 나중에 오류의 연쇄를 야기 할 수 있으며 처음부터 오류를 일으키지 않고 나중에 오류를 수정하려고 시도하는 것은 좋지 않습니다. –

답변

14

당신은 당신의 bankAccount 헤더 파일에

#include <string> 

필요하고, std::string로 문자열을 참조하십시오.

#ifndef H_bankAccount; 
#define H_bankAccount; 

#include <string> 

class bankAccount 
{ 
public: 
    std::string getAcctOwnersName() const; 

    .... 

헤더에 헤더가 포함되면 더 이상 구현 파일에 포함 할 필요가 없습니다.

+0

좋아요. 문자열 형식 앞에 내 헤더 파일 코드에 std :: string을 추가했는데 anyting이 변경되지 않았습니다. –

+2

이제 고맙겠습니다. –