Click to See Complete Forum and Search --> : ms visual 6.0


f15e
09-18-2002, 08:07 PM
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

dighn
09-18-2002, 08:16 PM
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)

f15e
09-18-2002, 08:30 PM
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!!

dighn
09-18-2002, 08:54 PM
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>

f15e
09-18-2002, 08:57 PM
Thanks for the info. dighn!!

dighn
09-18-2002, 08:57 PM
Originally posted by f15e
Thanks for the info. dighn!!

np :)

Royal Oaks
09-18-2002, 11:25 PM
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.

biosx
09-19-2002, 02:01 AM
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.