I wrote my project using a simple editor and I compile them by using Microsoft vc++ compiler through command line interface, I am getting the following error:
/out:Main.exe Main.obj
Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Ac count::debit(int)" (?debit@Account@@QAEXH@Z) referenced in function _main
Main.obj : error LNK2019: unresolved external symbol "public: int __thiscall Acc ount::getBalance(void)" (?getBalance@Account@@QAEHXZ) referenced in function _main
Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Account ::Account(int)" (??0Account@@QAE@H@Z) referenced in function _main Main.exe : fatal error LNK1120: 3 unresolved externals
Here is the code:
//File : Account.h
class Account{
public:
Account( int );
void credit( int );
void debit( int );
int getBalance();
private:
int balance;
};
//File:Account.cpp
#include<iostream>
using std::cout;
using std::endl;
#include "Account.h"
Account::Account( int initialbalance ){
balance = 0;
if( initialbalance > 0 )
balance = initialbalance;
if ( initialbalance < 0 )
cout<<"Initial Balance is empty\n"<<endl;
}
void Account::credit( int amount ){
balance = balance + amount;
}
void Account::debit( int amount ){
if( amount <= balance )
balance = balance - amount;
else
cout<<"Debit amount exceed balance amount\n"<<endl;
}
int Account::getBalance(){
return balance;
}
//File : Main.cpp
#include<iostream>
using std::cout;
using std::endl;
using std::cin;
#include "Account.h"
int main(){
Account obj(50);
cout<<"Account balance Rs. "<<obj.getBalance()<<"\n"<<endl;
int withdraw;
cout<<"Withdrawal amount for your account\n"<<endl;
cin>>withdraw;
cout<<"Withdrawing ....."<<endl;
obj.debit( withdraw );
cout<<"Final account balance : "<<obj.getBalance()<<endl;
return 0;
}
I have first compiled Account.cpp by using "cl /LD Account.cpp" , then when i try to compile "Main.cpp" I get these error , to be specific I want to know how to use a compiled .dll or .obj file in my client code that uses these compiled files when their source code is not available .
Thanks in advance.