After a few months of learning and practicing C++ with the book C++ Primer Plus through Chapter 7, I decided to do myself a little simple program.
I started with the decision to try splitting my program into multiple files, and I decided to collect all shared declarations/definitions (*) into header files, and that is where the problem started.
The first header file created (let's call it headerFile.h), the one I'm working on, has declarations/definitions like these:
enum QUALITY {QUALITY_1, QUALITY_2, QUALITY_3};
enum QUANTITY {QUANTITY_1, QUANTITY_2, QUANTITY_3, QUANTITY_4};
struct myStruct
{
int myInt;
int myOtherInt1, myOtherInt2;
QUALITY myQuality;
QUANTITY myQuantity;
std::string myString;
};
myStruct myStructures[13];
Then, below those lines, I did something like these:
myStructures[1].myInt = 1;
myStructures[1].myOtherInt1 = 2; myStructures[1].myOtherInt2 = 3;
myStructures[1].myQuality = QUALITY_1;
myStructures[1].myQuantity = QUALITY_3;
myStructures[1].myString = "Sparkles! Wee!";
I'm using VS2010, with this header file added in the Header Files folder of an empty project, a main .cpp in the source files project.
In the editor tab for headerFile.h, the lines in the upper code are underlined (by the red curvy one that underlines errors) like this:
myStructures[1].myInt = 1;
(The structure array name and the dot)
Every single statement that assign a value to a structure field (**) are all underlined that way. When hovered over those underlined structure array name, VS2010 says something like this:
int myStructures[1]
Error: This declaration has no storage class or type specifier.
And something like this over the underlined dots: Error: expected a declaration
What is wrong? What does those errors mean? I don't understand them one bit.
I searched around the net and there are mentions of typedef, but aren't myStruct, QUALITY and QUANTITY names of new types already? Does these have anything to do with header files?
And, why is myStructures[1] identified as int?
(*) Can anyone help me to understand deeply the concepts of declaration, definition,
(**) and initialization? Is assigning something to a structure field initialization?
One more thing. C++ Primer Plus says that C++ header files are without .h extension. Why do we have to add .h to our headers, if we are writing C++, not C, programs?