I'm thinking this is a problem with pre-compiled headers is VS...
Errors:
Code:
1>------ Build started: Project: 5.3, Configuration: Debug Win32 ------
1>Compiling...
1>ISBN.cpp
1>Book.cpp
1>Generating Code...
1>Skipping... (no relevant changes detected)
1>5.3.cpp
1>Linking...
1>ISBN.obj : error LNK2005: "public: __thiscall ISBN::ISBN(char * const)" (??0ISBN@@QAE@QAD@Z) already defined in 5.3.obj
1>ISBN.obj : error LNK2005: "public: __thiscall ISBN::ISBN(void)" (??0ISBN@@QAE@XZ) already defined in 5.3.obj
1>ISBN.obj : error LNK2005: "public: bool __thiscall ISBN::compareTo(class ISBN)" (?compareTo@ISBN@@QAE_NV1@@Z) already defined in 5.3.obj
1>ISBN.obj : error LNK2005: "public: __thiscall ISBN::~ISBN(void)" (??1ISBN@@QAE@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: __thiscall ISBN::ISBN(char * const)" (??0ISBN@@QAE@QAD@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: __thiscall ISBN::ISBN(void)" (??0ISBN@@QAE@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: bool __thiscall ISBN::compareTo(class ISBN)" (?compareTo@ISBN@@QAE_NV1@@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: __thiscall ISBN::~ISBN(void)" (??1ISBN@@QAE@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: __thiscall Book::Book(unsigned char,unsigned char,unsigned char,float,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char * const)" (??0Book@@QAE@EEEMV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00QAD@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: __thiscall Book::~Book(void)" (??1Book@@QAE@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: void __thiscall Book::setDate(char,char,char)" (?setDate@Book@@QAEXDDD@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: char * __thiscall Book::getDate(char *)" (?getDate@Book@@QAEPADPAD@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: void __thiscall Book::setPrice(float)" (?setPrice@Book@@QAEXM@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: float __thiscall Book::getPrice(void)" (?getPrice@Book@@QAEMXZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: void __thiscall Book::setAuthor(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setAuthor@Book@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Book::getAuthor(void)" (?getAuthor@Book@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: void __thiscall Book::setTitle(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setTitle@Book@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Book::getTitle(void)" (?getTitle@Book@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: void __thiscall Book::setPublisher(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setPublisher@Book@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Book::getPublisher(void)" (?getPublisher@Book@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: void __thiscall Book::setCity(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setCity@Book@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Book::getCity(void)" (?getCity@Book@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: class ISBN __thiscall Book::getISBN(void)" (?getISBN@Book@@QAE?AVISBN@@XZ) already defined in 5.3.obj
1>Book.obj : error LNK2005: "public: bool __thiscall Book::compareTo(class Book)" (?compareTo@Book@@QAE_NV1@@Z) already defined in 5.3.obj
1>C:\Users\Alex Smith\Documents\Visual Studio 2008\Projects\5.3\Debug\5.3.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://c:\Users\Alex Smith\Documents\Visual Studio 2008\Projects\5.3\5.3\Debug\BuildLog.htm"
1>5.3 - 25 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
book.cpp:
Code:
#include "StdAfx.h"
#include "Book.h"
using namespace std;
Book::Book(unsigned char month, unsigned char day, unsigned char year, float price, string author, string title, string city, char isbn[11])
{
this->month = month;
this->day = day;
this->year = year;
this->price = price;
this->author = author;
this->title = title;
this->city = city;
this->isbn = ISBN(isbn);
}
Book::~Book(void)
{
free(date);
date = NULL;
}
void Book::setDate(char month, char day, char year)
{
this->month = month;
this->day = day;
this->year = year;
}
char* Book::getDate(char *date)
{
date = new char(10);
sprintf_s(date, sizeof(date), "&d-%d-%d", day, month, year);
return date;
}
void Book::setPrice(float price) { this->price = price; }
float Book::getPrice() { return price; }
void Book::setAuthor(string author) { this->author = author; }
string Book::getAuthor() { return author; }
void Book::setTitle(string title) { this->title = title; }
string Book::getTitle() { return title; }
void Book::setPublisher(string publisher) { this->publisher = publisher; }
string Book::getPublisher() { return publisher; }
void Book::setCity(string city) { this->city = city; }
string Book::getCity() { return city; }
ISBN Book::getISBN() { return isbn; }
bool Book::compareTo(Book other)
{
return (isbn.compareTo(other.getISBN()));
}
Book.h:
Code:
#pragma once
#include <string>
#include "ISBN.cpp"
using namespace std;
class Book
{
public:
Book(unsigned char month, unsigned char day, unsigned char year, float price, string author, string title, string city, char isbn[11]);
~Book(void);
void setDate(char month, char day, char year);
char* getDate(char *date);
void setPrice(float price);
float getPrice();
void setAuthor(string author);
string getAuthor();
void setTitle(string title);
string getTitle();
void setPublisher(string publisher);
string getPublisher();
void setCity(string city);
string getCity();
ISBN getISBN();
bool compareTo(Book other);
private:
char month, day, year, *date;
float price;
string author;
string title;
string publisher;
string city;
ISBN isbn;
};
ISBN.cpp:
Code:
#include "StdAfx.h"
#include "ISBN.h"
#include <string>
ISBN::ISBN(char str[11])
{
char tmp[5];
int sum = 0;
for(int i = 0; i < 11; i++)
{
strncpy_s(tmp, str+i, 1);
sum = sum + atoi(tmp) * (i + 1);
}
if (sum / 11 == 10)
check = 'X';
else
check = sum / 11;
strncpy_s(tmp, str, 1);
group = atoi(tmp);
strncpy_s(tmp, str+2, 3);
publisher = atoi(tmp);
strncpy_s(tmp, str+6, 5);
id = atoi(tmp);
}
ISBN::ISBN(void)
{
}
bool ISBN::compareTo(ISBN other)
{
if(group == other.group && publisher == other.publisher && id == other.id)
return true;
else
return false;
}
ISBN::~ISBN(void)
{
}
ISBN.h:
Code:
#pragma once
class ISBN
{
public:
ISBN(char str[11]);
ISBN(void);
~ISBN(void);
char* getISBN(void);
bool checkISBN(void);
bool compareTo(ISBN other);
private:
char check;
unsigned char group;
unsigned short publisher;
unsigned int id;
};
Any ideas?
TIA