声明与类型不兼容

时间:2013-05-08 12:26:45

标签: c++ string types

头文件:

#ifndef H_bankAccount;
#define H_bankAccount;


class bankAccount
{
public:
    string getAcctOwnersName() const;
    int getAcctNum() const;
    double getBalance() const;
    virtual void print() const;

    void setAcctOwnersName(string);
    void setAcctNum(int);
    void setBalance(double);

    virtual void deposit(double)=0;
    virtual void withdraw(double)=0;
    virtual void getMonthlyStatement()=0;
    virtual void writeCheck() = 0;
private:
    string acctOwnersName;
    int acctNum;
    double acctBalance;
};
#endif

cpp文件:

#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下收到错误,声明该声明与“&lt; error-type&gt; bankAccount :: getAcctOwnersName()const”不兼容。

1 个答案:

答案 0 :(得分:19)

你需要

#include <string>

在您的bankAccount标头文件中,并将字符串称为std::string

#ifndef H_bankAccount;
#define H_bankAccount;

#include <string>

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

   ....

一旦它包含在标题中,您就不再需要将其包含在实现文件中。