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".

2

3 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.

2

I've found that when a private member variable and a member function have the same name the IDE gives me the "incompatible" error, perhaps that is what you are experiencing...

Sometimes this error occur because it's vary from machine to machine. Your program will work fine if you declare your class and all of its implementations in one file instead doing declaration of class in other file and linked it with your driver file. Again: This is totally machine dependent error. In visual studio 2012 you will face this kind of error because it not work for these files while in other versions of vs you will not face any error type exception.

Hope it's worth.....

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy