Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaration is incompatible with type

Tags:

c++

string

types

header file:

#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 file:

#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;
}

Please help i get an error under getAcctOwnersName, and setAcctOwnersName stating that the declaration is incompatible with "< error-type > bankAccount::getAcctOwnersName() const".

like image 881
Eric Oudin Avatar asked May 08 '13 12:05

Eric Oudin


1 Answers

You need to

#include <string>

in your bankAccount header file, and refer to the strings as std::string.

#ifndef H_bankAccount;
#define H_bankAccount;

#include <string>

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

   ....

once it is included in the header, you no longer need to include it in the implementation file.

like image 97
juanchopanza Avatar answered Sep 21 '22 09:09

juanchopanza