I am using Boreland 5.02 and am having difficulty compiling and linking a project. This is the first time I am trying this, prior to this all my programming was done in one .c file. I have only written in c so far, no c++.
I have 3 .cpp files and 2 header files in my project, the programs compile ok, but I receive an error when it tries to link. The files I have came from my instructor, who uses microsoft visual C++.
Here is the output when I try to compile and link the code. The last section is what is giving me trouble, the errrors are at the bottom. I have also included the .cpp and .h files below, there is not much to them, just the beginning of a program. but it does compile and link for my instructor.
Info :Making...
Info :atm.cpp: rebuild due to dependency atm.cpp
Info : atm.cpp: cache age 9:39:00 PM 9/13/01, disk age 9:40:21 PM 9/13/01
Info :Compiling C:\paul\csu\cis569 _obj_or_prog_with_c++\misc\atm example\atm.cpp
Warn : string.h(549,3):Functions containing for are not expanded inline
Warn : string.h(557,3):Functions containing while are not expanded inline
Warn : string.h(563,3):Functions containing for are not expanded inline
Warn : string.h(575,3):Functions containing for are not expanded inline
Warn : string.h(742,96):Conversion may lose significant digits
Warn : string.h(768,96):Conversion may lose significant digits
Warn : string.cc(658,2):Cannot create pre-compiled header: code in header
Warn : atm.cpp(24,2):Parameter 'argc' is never used
Warn : atm.cpp(24,2):Parameter 'argv' is never used
Info :account.cpp: rebuild due to dependency account.cpp
Info : account.cpp: cache age 10:52:08 PM 9/12/01, disk age 9:40:23 PM 9/13/01
Info :Compiling C:\paul\csu\cis569 _obj_or_prog_with_c++\misc\atm example\account.cpp
Warn : string.h(549,3):Functions containing for are not expanded inline
Warn : string.h(557,3):Functions containing while are not expanded inline
Warn : string.h(563,3):Functions containing for are not expanded inline
Warn : string.h(575,3):Functions containing for are not expanded inline
Warn : string.h(742,96):Conversion may lose significant digits
Warn : string.h(768,96):Conversion may lose significant digits
Warn : string.cc(658,2):Cannot create pre-compiled header: code in header
Info :Transferring to C:\BC5\BIN\tlink.exe @c:\PAUL\CSU\CIS569~1\MISC\ATMEXA~1\TEST.R$P
Error: (1,1):std:perator <<(ostream near&,const std::basic_string<char,std::string_char_traits<cha r>>near&) defined in module error.cpp is duplicated in module atm.cpp
Error: (1,1):std:perator >>(istream near&,std::basic_string<char,std::string_char_trai ts<char>>near&) defined in module error.cpp is duplicated in module atm.cpp
Fatal: (1,1):Bad object file record in module atm.cpp near module file offset 0x00011DC4
Code for ATM example
atm.cpp
// ATM.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "account.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
Account acct1("123");
acct1.Deposit(100.0);
acct1.CurrentBalance();
cout << "Balance: " << acct1.CurrentBalance() << endl;
acct1.Withdraw(50.0);
cout << "Balance: " << acct1.CurrentBalance() << endl;
return 0;
}
account.cpp
// ATM.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "account.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
Account acct1("123");
acct1.Deposit(100.0);
acct1.CurrentBalance();
cout << "Balance: " << acct1.CurrentBalance() << endl;
acct1.Withdraw(50.0);
cout << "Balance: " << acct1.CurrentBalance() << endl;
return 0;
}
Error.cpp
// Error.cpp: implementation of the CError class.
//
//////////////////////////////////////////////////////////////////////
//#include "stdafx.h"
#include <iostream>
#include "Error.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CError::CError()
{
}
CError::CError(string strError)
{
}
CError::~CError()
{
}
void CError::ShowReason() {
cout << m_ErrorMsg.c_str();
}
void CError::ShowReason(string strError) {
cout << strError.c_str();
}
account.h
// Account.h: interface for the Account class.
//
//////////////////////////////////////////////////////////////////////
//#if !defined(AFX_ACCOUNT_H__7A3FE7A0_9661_4A17_865B_D9 9F043A66BC__INCLUDED_)
//#define AFX_ACCOUNT_H__7A3FE7A0_9661_4A17_865B_D99F043A66B C__INCLUDED_
#if !defined(account_incl)
#define account_incl
//#if _MSC_VER > 1000
//#pragma once
//#endif // _MSC_VER > 1000
#include <string>
using namespace std;
class Account
{
public:
Account();
Account(string AcctNo);
virtual ~Account();
bool Deposit( double Amount );
double CurrentBalance( void );
bool Withdraw ( double Amount );
private:
string m_AccountNo;
double m_Balance;
};
#endif // !defined(AFX_ACCOUNT_H__7A3FE7A0_9661_4A17_865B_D9 9F043A66BC__INCLUDED_)
error.h
// Error.h: interface for the CError class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ERROR_H__2E7F9FFC_68D8_4D87_896D_25BA 04F40EEB__INCLUDED_)
#define AFX_ERROR_H__2E7F9FFC_68D8_4D87_896D_25BA04F40EEB_ _INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <string>
using namespace std;
class CError
{
public:
CError();
CError(string strError);
virtual ~CError();
void ShowReason();
void ShowReason(string strError);
private:
string m_ErrorMsg;
};
#endif // !defined(AFX_ERROR_H__2E7F9FFC_68D8_4D87_896D_25BA 04F40EEB__INCLUDED_)