|
-
Catfish
ms visual 6.0
I am using MS Visual C++ 6.0. Can anyone tell me why I am getting these errors within my header file(these are only a few of the errors):
rror C2146: syntax error : missing ';' before identifier 'bkIsbn'
c:\program files\microsoft visual studio\myprojects\book\book.h(13) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\book\book.h(13) : error C2501: 'bkIsbn' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\book\book.h(14) : error C2146: syntax error : missing ';' before identifier 'bkTitle'
c:\program files\microsoft visual studio\myprojects\book\book.h(14) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\book\book.h(14) : error C2501: 'bkTitle' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\book\book.h(15) : error C2146: syntax error : missing ';' before identifier 'bkAuthor'
c:\program files\microsoft visual studio\myprojects\book\book.h(15) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\book\book.h(15) : error C2501: 'bkAuthor' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\book\book.h(16) : error C2146: syntax error : missing ';' before identifier 'bkPublisher'
Here is what I have in my header file:
#ifndef _BOOK
#define _BOOK
class Book
{
private:
string bkIsbn;
string bkTitle;
string bkAuthor;
string bkPublisher;
int bkPubYr;
int bkNumInStock;
int counter;
double bkPrice;
public:
Book(string, string, string, string, int, double, int);
~Book();
};
#endif
-
Mako Shark
yeah. to use string you need to include <string> then put "using namespace std;" after it (there are other ways but this shoudbe good enough)
-
Catfish
I didn't think you needed that info within a .h file. The reason I say this is that I don't need it with the g++ compiler at school. All I needed was what you see in my post above. I will try and see what happens.
THANKS!!
-
Mako Shark
well that's probably because you included <string> somewhere before you included the header file... it depends on how you place the header files in order in the cpp file. i wouldn't rely on that so i'd put it in the h file anyway to be sure. it's a good practice anyway because you are using strings in your .h file.
oh one other thing, you must have a "using namespace std" if you are not using g++. in my experience g++ for some reason ignore the namespace of the std library which is an incorrect behavior. at least i found this with g++ 2.9x, which is the mst common i believe. and make sure you are including <string>, not <string.h>
Last edited by dighn; 09-18-2002 at 08:57 PM.
.
-
Catfish
Thanks for the info. dighn!!
-
Mako Shark
Originally posted by f15e
Thanks for the info. dighn!!
np
-
Hammerhead Shark
Man ive noticed while doing some programming on Visual C++ 6.0 that i will get errors in places where there arent any. Granted i am using the introductory version that came with my book, but still. I will finish editing a program, and then i will go back to build and it will sometimes tell me i have errors when i dont. This even happens sometimes after i save the changes. It usually doesnt matter. I know for a fact that the compiler is making errors, because i will copy and paste what i have done and it will show up fine when i go to a new workspace. I dont know if anyhone has an similar problems, but i imagine this is only seen in the introductory version.
-
Reef Shark
The only time I had a problem with a compiler being lame was with Borland's free command line tools (C++ builder 5.5).
It seriously wasn't generating the right object code and the values that I were printing (that were supposed to be various data) were showing up as zero's. I ftp'd the code (unaltered) to my school's solaris machine and compiled it there. Surprisingly, when I ran the program, it worked perfectly.
I got rid of BCB and got mingw.
## root is the greed of all evil ##
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|