-
Linker error (?)
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
-
You should be including headers (for declarations), not cpp files (implementations).
BTW, ISBN should be 13 digits nowadays.
-
Yeah, you get that kind of thing happening when you have
#include "ISBN.cpp"
.cpp files go in the project, so they can be compiled ONCE only.
If you start including source code, there is a very real chance you end up compiling the same code over and over, and leading to "multiply declared symbols".
-
I thought that looked weird (it's the way VS setup)... and the ISBN is only 11 because the check (last number) and dash are added on later.
-
How do you guys suggest I rearrange includes? I'm working on it right now but without much luck... TIA
-
Right now you have book.cpp including book.h which includes isbn.cpp which includes isbn.h.
- All headers should have inclusion guards present (don't know how portable #pragma once is).
- Book.H should not include ISBN.cpp but rather ISBN.H
- It looks like your 5.3.cpp file is including both ISBN.cpp and book.cpp (at the very least it is probably including book.cpp) but I can't confirm this, just guessing based on the output from the build. This needs to include book.h instead at the least but can also include isbn.h.
- Any cpp file should be listed in your project's source files.
- Remove the using namespace std; bit in book.h and explicitly qualify any necessary items, i.e. string objects.
-
Thanks for the advice, added inclusion gaurds
now it looks something like this:
main --> Book.h --> Book.cpp
but now all the elements in the .cpp are not declared and/or are invalid... Did I miss something here?
-
Post the same build log/files that you did in your original post so we can see what you've done.
-
Include guards don't help.
If you're compiling foo.cpp, all include guards will do is ensure foo.cpp doesn't get more than one copy of book.cpp.
If you then compile bar.cpp, which also includes book.h (and the .cpp), you've got ANOTHER copy of the functions, and you're right back at the "multiply declared" errors.
DO NOT #include source code!
Add your .cpp files to the project, then fix it so each .cpp file includes the header files it needs.
-
(switched to mac in the middle)
main.cpp:
Code:
#include <iostream>
#include "Book.h"
#include "ISBN.h"
int main (int argc, char * const argv[]) {
// insert code here...
Book myBook = Book();
std::cout << "Hello, World!\n";
return 0;
}
Book.h:
Code:
#include <iostream>
#include "Book.h"
#include "ISBN.h"
int main (int argc, char * const argv[]) {
// insert code here...
Book myBook = Book();
std::cout << "Hello, World!\n";
return 0;
}
ISBN.h
Code:
#include "ISBN.cpp"
#ifndef _ISBN_H_
#define _ISBN_H_
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;
};
#endif
Book.cpp:
Code:
#include "ISBN.cpp"
#ifndef _ISBN_H_
#define _ISBN_H_
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;
};
#endif
ISBN.cpp:
Code:
#include <string>
ISBN::ISBN(char str[11])
{
char tmp[5];
int sum = 0;
for(int i = 0; i < 11; i++)
{
strncpy(tmp, str+i, 1);
sum = sum + atoi(tmp) * (i + 1);
}
if (sum / 11 == 10)
check = 'X';
else
check = sum / 11;
strncpy(tmp, str, 1);
group = atoi(tmp);
strncpy(tmp, str+2, 3);
publisher = atoi(tmp);
strncpy(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)
{
}
Errors:
Code:
Line Location main.cpp:10: warning: statement is a reference, not call, to function 'Book'
Line Location main.cpp:10: error: expected `;' before 'myBook'
Line Location ISBN.cpp:34: error: expected constructor, destructor, or type conversion before '::' token
Line Location ISBN.cpp:34: error: expected constructor, destructor, or type conversion before '::' token
Line Location ISBN.cpp:34: error: expected constructor, destructor, or type conversion before '::' token
Line Location ISBN.cpp:28: error: expected ',' or ';' before '{' token
Line Location ISBN.cpp:28: error: expected ',' or ';' before '{' token
Line Location ISBN.cpp:28: error: expected ',' or ';' before '{' token
Line Location ISBN.cpp:27: error: cannot resolve overloaded function 'ISBN' based on conversion to type 'bool'
Line Location ISBN.cpp:27: error: cannot resolve overloaded function 'ISBN' based on conversion to type 'bool'
Line Location ISBN.cpp:27: error: expected `)' before 'other'
Line Location ISBN.cpp:27: error: 'ISBN' is not a class or namespace
Line Location ISBN.cpp:27: error: expected `)' before 'other'
Line Location ISBN.cpp:27: error: 'ISBN' is not a class or namespace
Line Location ISBN.cpp:27: error: 'ISBN' is not a class or namespace
Line Location ISBN.cpp:27: error: cannot resolve overloaded function 'ISBN' based on conversion to type 'bool'
Line Location ISBN.cpp:27: 'bool compareTo' previously defined here
Line Location ISBN.cpp:27: 'bool compareTo' previously defined here
Line Location ISBN.cpp:27: error: expected `)' before 'other'
Line Location ISBN.cpp:26: warning: control reaches end of non-void function
Line Location ISBN.cpp:26: warning: control reaches end of non-void function
Line Location ISBN.cpp:26: warning: control reaches end of non-void function
Line Location ISBN.cpp:24: error: 'ISBN' is not a class or namespace
Line Location ISBN.cpp:24: error: ISO C++ forbids declaration of 'ISBN' with no type
Line Location ISBN.cpp:24: error: ISO C++ forbids declaration of 'ISBN' with no type
Line Location ISBN.cpp:24: error: 'ISBN' is not a class or namespace
Line Location ISBN.cpp:24: error: ISO C++ forbids declaration of 'ISBN' with no type
Line Location ISBN.cpp:24: error: 'ISBN' is not a class or namespace
Line Location ISBN.cpp:23: warning: control reaches end of non-void function
Line Location ISBN.cpp:23: warning: control reaches end of non-void function
Line Location ISBN.cpp:23: warning: control reaches end of non-void function
Line Location ISBN.cpp:22: error: 'id' was not declared in this scope
Line Location ISBN.cpp:22: error: 'id' was not declared in this scope
Line Location ISBN.cpp:22: error: 'id' was not declared in this scope
Line Location ISBN.cpp:20: error: 'publisher' was not declared in this scope
Line Location ISBN.cpp:20: error: 'publisher' was not declared in this scope
Line Location ISBN.cpp:20: error: 'publisher' was not declared in this scope
Line Location ISBN.cpp:18: error: 'group' was not declared in this scope
Line Location ISBN.cpp:18: error: 'group' was not declared in this scope
Line Location ISBN.cpp:18: error: 'group' was not declared in this scope
Line Location ISBN.cpp:16: error: 'check' was not declared in this scope
Line Location ISBN.cpp:16: error: 'check' was not declared in this scope
Line Location ISBN.cpp:16: error: 'check' was not declared in this scope
Line Location ISBN.cpp:14: error: 'check' was not declared in this scope
Line Location ISBN.cpp:14: error: 'check' was not declared in this scope
Line Location ISBN.cpp:14: error: 'check' was not declared in this scope
Line Location ISBN.cpp:4: error: 'ISBN' has not been declared
Line Location ISBN.cpp:4: error: 'ISBN' has not been declared
Line Location ISBN.cpp:4: error: 'ISBN' has not been declared
Line Location ISBN.cpp:4: error: ISO C++ forbids declaration of 'ISBN' with no type
Line Location ISBN.cpp:4: error: ISO C++ forbids declaration of 'ISBN' with no type
Line Location ISBN.cpp:4: error: ISO C++ forbids declaration of 'ISBN' with no type
Line Location Book.h:37: error: 'ISBN' does not name a type
Line Location Book.h:28: error: 'ISBN' does not name a type
Line Location Book.cpp:42: error: redefinition of 'bool compareTo'
Line Location Book.cpp:42: error: expected `)' before 'other'
Line Location Book.cpp:42: error: 'Book' is not a class or namespace
Line Location Book.cpp:42: error: 'Book' is not a class or namespace
Line Location Book.cpp:42: error: expected `)' before 'other'
Line Location Book.cpp:42: error: redefinition of 'bool compareTo'
Line Location Book.cpp:41: error: 'ISBN' does not name a type
Line Location Book.cpp:41: error: 'ISBN' does not name a type
Line Location Book.cpp:40: error: 'string' does not name a type
Line Location Book.cpp:40: error: 'string' does not name a type
Line Location Book.cpp:39: error: expected ',' or ';' before '{' token
Line Location Book.cpp:39: error: variable or field 'setCity' declared void
Line Location Book.cpp:39: error: 'string' was not declared in this scope
Line Location Book.cpp:39: error: 'Book' is not a class or namespace
Line Location Book.cpp:39: error: expected ',' or ';' before '{' token
Line Location Book.cpp:39: error: 'Book' is not a class or namespace
Line Location Book.cpp:39: error: 'string' was not declared in this scope
Line Location Book.cpp:39: error: variable or field 'setCity' declared void
Line Location Book.cpp:38: error: 'string' does not name a type
Line Location Book.cpp:38: error: 'string' does not name a type
Line Location Book.cpp:37: error: variable or field 'setPublisher' declared void
Line Location Book.cpp:37: error: 'Book' is not a class or namespace
Line Location Book.cpp:37: error: 'string' was not declared in this scope
Line Location Book.cpp:37: error: variable or field 'setPublisher' declared void
Line Location Book.cpp:37: error: 'Book' is not a class or namespace
Line Location Book.cpp:37: error: expected ',' or ';' before '{' token
Line Location Book.cpp:37: error: 'string' was not declared in this scope
Line Location Book.cpp:37: error: expected ',' or ';' before '{' token
Line Location Book.cpp:36: error: 'string' does not name a type
Line Location Book.cpp:36: error: 'string' does not name a type
Line Location Book.cpp:35: error: 'Book' is not a class or namespace
Line Location Book.cpp:35: error: variable or field 'setTitle' declared void
Line Location Book.cpp:35: error: 'string' was not declared in this scope
Line Location Book.cpp:35: error: expected ',' or ';' before '{' token
Line Location Book.cpp:35: error: expected ',' or ';' before '{' token
Line Location Book.cpp:35: error: 'string' was not declared in this scope
Line Location Book.cpp:35: error: variable or field 'setTitle' declared void
Line Location Book.cpp:35: error: 'Book' is not a class or namespace
Line Location Book.cpp:34: error: 'string' does not name a type
Line Location Book.cpp:34: error: 'string' does not name a type
Line Location Book.cpp:33: error: 'string' was not declared in this scope
Line Location Book.cpp:33: error: 'Book' is not a class or namespace
Line Location Book.cpp:33: error: variable or field 'setAuthor' declared void
Line Location Book.cpp:33: error: 'string' was not declared in this scope
Line Location Book.cpp:33: error: expected ',' or ';' before '{' token
Line Location Book.cpp:33: error: variable or field 'setAuthor' declared void
Line Location Book.cpp:33: error: 'Book' is not a class or namespace
Line Location Book.cpp:33: error: expected ',' or ';' before '{' token
Line Location Book.cpp:32: error: 'price' was not declared in this scope
Line Location Book.cpp:32: error: 'Book' is not a class or namespace
Line Location Book.cpp:32: error: 'price' was not declared in this scope
Line Location Book.cpp:32: error: 'Book' is not a class or namespace
Line Location Book.cpp:31: error: invalid use of 'this' in non-member function
Line Location Book.cpp:31: error: 'Book' is not a class or namespace
Line Location Book.cpp:31: error: 'Book' is not a class or namespace
Line Location Book.cpp:31: error: invalid use of 'this' in non-member function
Line Location Book.cpp:28: error: 'year' was not declared in this scope
Line Location Book.cpp:28: error: 'month' was not declared in this scope
Line Location Book.cpp:28: error: 'month' was not declared in this scope
Line Location Book.cpp:28: error: 'day' was not declared in this scope
Line Location Book.cpp:28: error: 'day' was not declared in this scope
Line Location Book.cpp:28: error: 'year' was not declared in this scope
Line Location Book.cpp:25: error: 'Book' is not a class or namespace
Line Location Book.cpp:25: error: 'Book' is not a class or namespace
Line Location Book.cpp:23: error: invalid use of 'this' in non-member function
Line Location Book.cpp:23: error: invalid use of 'this' in non-member function
Line Location Book.cpp:22: error: invalid use of 'this' in non-member function
Line Location Book.cpp:22: error: invalid use of 'this' in non-member function
Line Location Book.cpp:21: error: invalid use of 'this' in non-member function
Line Location Book.cpp:21: error: invalid use of 'this' in non-member function
Line Location Book.cpp:19: error: 'Book' is not a class or namespace
Line Location Book.cpp:19: error: 'Book' is not a class or namespace
Line Location Book.cpp:14: error: expected constructor, destructor, or type conversion before '::' token
Line Location Book.cpp:14: error: expected constructor, destructor, or type conversion before '::' token
Line Location Book.cpp:13: warning: control reaches end of non-void function
Line Location Book.cpp:13: warning: control reaches end of non-void function
Line Location Book.cpp:12: error: invalid use of 'this' in non-member function
Line Location Book.cpp:12: error: invalid use of 'this' in non-member function
Line Location Book.cpp:11: error: invalid use of 'this' in non-member function
Line Location Book.cpp:11: error: invalid use of 'this' in non-member function
Line Location Book.cpp:10: error: invalid use of 'this' in non-member function
Line Location Book.cpp:10: error: invalid use of 'this' in non-member function
Line Location Book.cpp:9: error: invalid use of 'this' in non-member function
Line Location Book.cpp:9: error: invalid use of 'this' in non-member function
Line Location Book.cpp:8: error: invalid use of 'this' in non-member function
Line Location Book.cpp:8: error: invalid use of 'this' in non-member function
Line Location Book.cpp:7: error: invalid use of 'this' in non-member function
Line Location Book.cpp:7: error: invalid use of 'this' in non-member function
Line Location Book.cpp:6: error: invalid use of 'this' in non-member function
Line Location Book.cpp:6: error: invalid use of 'this' in non-member function
Line Location Book.cpp:5: error: invalid use of 'this' in non-member function
Line Location Book.cpp:5: error: invalid use of 'this' in non-member function
Line Location Book.cpp:3: error: 'Book' has not been declared
Line Location Book.cpp:3: error: 'string' has not been declared
Line Location Book.cpp:3: error: 'string' has not been declared
Line Location Book.cpp:3: error: 'string' has not been declared
Line Location Book.cpp:3: error: ISO C++ forbids declaration of 'Book' with no type
Line Location Book.cpp:3: error: ISO C++ forbids declaration of 'Book' with no type
Line Location Book.cpp:3: error: 'string' has not been declared
Line Location Book.cpp:3: error: 'string' has not been declared
Line Location Book.cpp:3: error: 'string' has not been declared
Line Location Book.cpp:3: error: 'Book' has not been declared
-
OK, a new more basics.
1. ONLY ONE file has a main().
2. book.cpp includes book.h, ISBN.cpp includes ISBN.h etc etc
3. If book.cpp NEEDS something from ISBN, then it includes ISBN.h
4. main.cpp, book.cpp, ISBN.cpp (and any other .cpp) go into the project settings->source files.
-
You're still including *.cpp files, and you shouldn't be.
book.h is including itself, and it shouldn't be.
There is an include outside of ISBN.h's include gaurds, and there shouldn't be.
ISBN.h is including ISBN.cpp, and it shouldn't be.
Same issue with book.cpp
Book.cpp isn't including Book.h, and it should be.
ISBN.cpp isn't including ISBN.h, and it should be.
-
I know there's only one main(), I switched between Mac and Windows in the middle (slightly different file names)
Includes should look like this:
main.cpp(whatever file contains main()):
-book.cpp
book.cpp:
-book.h
-ISBN.h
ISBN.cpp:
-ISBN.h
ISBN.h:
-none
book.h:
(needs something from ISBN, but including either ISBN file causes problems, not having one in there doesn't work)
and to top it off I think I may have copied and pasted some of those files incorrectly
(back in windows)
(pasted correctly this time)
main:
Code:
#pragma once
#include "Book.cpp"
#include "StdAfx.h"
Book.cpp:
Code:
#pragma once
#include "StdAfx.h"
#include "Book.h"
#include "ISBN.h"
book.h:
Code:
#pragma once
#include <string>
#include "ISBN.h"
using namespace std;
ISBN.cpp:
Code:
#include "StdAfx.h"
#pragma once
#include "ISBN.h"
#include <string>
I apologize if I'm a little thick but I didn't sleep last night and it's really catching up with me.
-
You're still including Book.cpp. Don't. Include book.h is you need to.
-
You keep asking for help, and keep ignoring the advice you are given :)
Some additional things besides what has already been said before:
No need to use this in .cpp files. The IDE will only compile each .cpp file once anyway. (unless you are including them in other .cpp files, like you've been told you shouldn't do)
Code:
#include "StdAfx.h"
If you are using precompiled headers then this has to be the first #include in every .cpp file or you will get a compilation error.