I think that you have a problem with line 36:
36 StatArray myArray(); /* constructor */
If you are intending to create an object called myArray of class StatArray
then that will not work. The compiler will in fact declare (but not define)
a function called myArray with no parameters but with a return type of
StatArray. The line should be changed to:
36 StatArray myArray; /* constructor */
No parenthesis. This is one of those strange cases, if the constructor
doesn't expect any parameters than omit the parenthesis.
To get the nested included to work you either need to include a
pre-processor directive or exclude the #include and declare the class
extern. The pre-processor directive is probably better here, and a good
habit to get into: so wrap each header file with the following type of code
#ifndef __STATARRAY_HPP
#define __STATARRAY_HPP
// put you class declaration
// and inline functions here
#endif
Essentially the first time in this creates a pre-processor variable called
__STATARRAY_HPP (use __DYNARRAY_HPP for your other file) the next time in
because the variable exists it doesn't declare the class (jumping directly
to the #endif directive) and thus it will avoid declaring the class a second
time.
I hope this helps.
--__--__--
Message: 2
From: "Daniel Anderson" <bt...@ca...>
To: <dev...@li...>
Date: Thu, 4 Apr 2002 20:21:22 -0500
Subject: [Dev-C++] Help me in deciphering complier error...
Hello coders,
I have run into a problem with a program I am writing. I have a parent
class, DynArray, that StatArray is derived from. dynarray.cpp is in one
file, statarray.cpp is in another. My main program has an #include
"statarray.cpp" statement, and statarray.cpp in turn #include's
"dynarray.cpp". When attempting to compile the program, I get the following
errors. I am guessing this type of error indicates that I might be mixing
types, but I can't figure out where and what I need to correct. Any help is
appreciated. Thanks!
Danny
main.cpp: In function `int main()':
main.cpp:38: conversion from `StatArray (*)()' to non-scalar type
`StatArray' requested
main.cpp:14: in passing argument 1 of `GetArray(StatArray &, ifstream &)'
main.cpp:40: conversion from `StatArray (*)()' to non-scalar type
`StatArray' requested
main.cpp:15: in passing argument 1 of `PrintArray(const StatArray &,
ofstream &)'
/* code fragment here: */
14 void GetArray(StatArray&, ifstream&);
15 void PrintArray(const StatArray&, ofstream&);
...
36 StatArray myArray(); /* constructor */
38 GetArray(myArray, inData);
40 PrintArray(myArray, outData);
/* func definitions empty */
void GetArray(StatArray& targetArray, ifstream& inData)
{}
void PrintArray(const StatArray& sourceArray, ofstream& outData)
{ }
|