On 2007-10-26 09:30, CuTe_Engineer wrote:
hii,
i have problem in dealing with protected data members & array
this is my prog i make it as a project file
my errors are mainly about declaration like :
c:\documents and settings\xppresp3\desktop
\ass2\ass2\gymnasiumimp.cpp(56) : error C2065: 'exercises' :
undeclared identifier
i didn`t understand why its undeclared while it`s a struct data
members and it should be public, but i use it in a class as an
protected array , so how can i declare it now ?
the header files :
#include<string>
#ifndef H_Gymnasium
#define H_Gymnasium
Move the include-guards above other includes.
using namespace std;
Do not use this in header-files, all files that includes your header
will have to live with the effects.
struct activities
{
string exercises;
int time;
};
class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
};
#endif
double Gymnasium:: calories()
{
int totalLost,Lostcalories ,i;
for(i=0 ,i<gymlength , i++)
gymarray[i]=exercises*time;
Like you said, exercises is a member in a struct, that means that you
have to have an instance of that struct to access it:
activities a;
a.exercises = "Jump";
As can be seen from the above example, exercises is a string, you can
not multiply a string with an integer.
--
Erik Wikstr??m- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -