C++/an error

Advertisement


Question
Hi
I made this code in Borland C++:

const pCount=3;
struct finance{
  unsigned int hourC;
  float pay;
  unsigned char hourR;
  unsigned short int rate;
}
struct clerk{
  struct finance fin;
  unsigned char fName[10],lName[15],pID[10];
  unsigned short int eYear;
  unsigned char marriage,childC;
} company[pCount];

But the compiler shows this error:
Too many types in declaration in struct clerk{

I used the help but I didn't get it.So what is the problem and what should I do?
Thanks
PS:is it possible to include just one function of a header file? I meen isn't it waste of memory when I include all the conio.h for example just to use clrscr(); !


Answer
BM,
1) The problem with your 'clerk' struct is relatively easy. You first declare 'struct clerk{', indicating to the compiler that everything following the { will be in the struct. However, on the next line, you're telling the compiler 'struct finance fin;'. This is where your problem is. Structs are usually used to create your own variables that have multiple characteristics, but the compiler doesn't understand that you want to declare an actual variable of type 'finance' within 'clerk'. It just sees 'struct finance fin;', and flips out because it thinks you're trying to declare a struct within another struct. If removing 'struct finance fin;' doesn't solve the problem, try breaking out the 'fName', 'lName', and 'pID' variables into different lines (i.e. you declare the variables independently and don't create/initialize them all with one 'unsigned char' statement).

2) It is not possible to include just one function from a header file. The compiler knows which code to include in the resulting .exe file from conio.h. So it grabs the proper code, uses it, then creates the .exe and ditches all the unneeded code. So while it seems like it'd be a waste of memory, it's really not. I hope this helps.

Best Of Luck,
Alan

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Alan F.

Expertise

Having problems with any basic or intermediate parts of C++? I can answer those questions for you using simple English. I have been taking C++ in school for a couple years, so I still remember what it was like to be a beginner (especially with C++, which is a difficult language)!

Experience

I have a C++ web page that discuses the basics of C++. The address is: http://www.afweb.net/complang/

©2016 About.com. All rights reserved.