inheritance problem with link error

this is my code it is not yet complete.

#ifndef FILE_H
#define FILE_H

#include<iostream>
#include<string>
using namespace std;

class file
{
protected:
string text;
string line;
string filename;
public:
file();
void setfile(string);
int fileMenu();
//void constrtoint(string tex);
void fileWrite(double tex);
void fileRead();
void fileEnter();


};
#endif


#ifndef BANK_H
#define BANK_H

#include<iostream>
#include<string>
#include"file.h"
using namespace std;

class bank : public file
{
private:
double withamount;
double depamount;
double balance;
string holdername;
string accountnum;
public:
bank();
bank(string name1, double balance1, string accountnum1);
double withdraw(double);
double deposit(double);
const void Fbalance();
const void print();
};
#endif


#ifndef MENU_H
#define MENU_H

#include "bank.h"
//#include "file.h"
#include <string>
using namespace std;

class menu : public bank
{
private:
string func;
public:
menu();
void main();
void mwithdraw();
void mdeposit();
void openfile();

};
#endif


#include"menu.h"
//#include"bank.h"
//#include"file.h"

#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
bank b1;
menu::menu()
{

}

void menu::main()
{
//system("cls");

cout << "Which would you like to do, withdraw, deposit, or see your transactions.\n";
cin >> func;

if (func == "withdraw")
{
mwithdraw();
}
else if(func == "deposit")
{
mdeposit();
}
else if (func == "transactions")
{
Fbalance();
openfile();
}
else if (func == " ")
{
cout << "Please make sure you enter in the correct choice";
}
}
void menu::mwithdraw()
{
string date, location;
double mamount=0;
cout << "Please enter the amount to withdraw \n";
cin >> mamount;
b1.withdraw(mamount);
//fileWrite(mamount);
}
void menu::mdeposit()
{
double amount;
string type;
cout << "Please enter amount to deposit and wether it is a check or cash.\n";
cin >> amount, type;
deposit(amount);


}
void menu::openfile()
{
string fileName;
cout << "Please enter in file to open:\n ";
cin >> fileName;
fileName += ".txt";
cout << fileName;
//setfile(fileName);

}



#include"file.h"
#include"bank.h"
#include"menu.h"

#include<iostream>
#include<fstream>
using namespace std;



void file::setfile(string fileName)
{
filename = fileName;
}
void file::fileWrite(double tex)
{
ofstream myfile2;
myfile2.open(filename.c_str(), fstream::app);
myfile2 << tex << "\n";
myfile2.close();

}
void file::fileRead()
{
ifstream myfile;
string line;
myfile.open(filename.c_str());
cout << "\n\n";
if (myfile.is_open())
{
while (getline(myfile, line))
{
cout << line << endl;
}
}
myfile.close();
cout << "\n\n";

}



#include"bank.h"
#include<iostream>
#include<string>
using namespace std;

bank::bank()
{

}
bank::bank(string name1, double balance1, string accountnum1)
{
holdername = name1;
balance = balance1;
accountnum = accountnum1;
}
double bank::withdraw(double withd)
{
balance -= withd;
cout << "The amount of " << withd << " dallors has been withdrawn. The remaining balance is:" << balance;
//system("pause");
return 0;
}
double bank::deposit(double deposit)
{
balance += deposit;
cout << "The amount you have deposited is " << deposit << ". The current balance is:" << balance;
//system("pause");
return 0;
}
const void bank::Fbalance()
{
cout << "The current balance is:" << balance << endl;
//system("pause");
}



I am using visual studio 2013 the problem seems to be in the bank.h where I use inheritance for file class
I am using visual studio 2013 the problem seems to be in the bank.h where I use inheritance for file class

What problem? You really should post the actual error--it's telling you what's wrong.
I get a link error when i try to have the file.h be inheritance by bank.h. in this section of code. i get the error:

Error 2 error LNK2019: unresolved external symbol "public: __thiscall file::file(void)" (??0file@@QAE@XZ) referenced in function "public: __thiscall bank::bank(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0bank@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N0@Z) F:\bugdet\ConsoleApplication1\bankSource.obj ConsoleApplication1





#ifndef BANK_H
#define BANK_H

#include<iostream>
#include<string>
#include"file.h"
using namespace std;

class bank : public file
{
private:
double withamount;
double depamount;
double balance;
string holdername;
string accountnum;
public:
bank();
bank(string name1, double balance1, string accountnum1);
double withdraw(double);
double deposit(double);
const void Fbalance();
const void print();
};
#endif
http://www.cplusplus.com/forum/general/113904/#msg622050
¿where is the definition for the file constructor?
Last edited on
Topic archived. No new replies allowed.