|
Prev: Why is bitset defined in the associative containers section?
Next: Suggestions on map template / Library
From: Kush on 19 Jul 2008 05:42 Hello, I am attempting to create a small program to teach a colleague how to program using C++ but I seem to be having my own difficulties with a compile error. It has been quite some time since I last wrote code in general, led alone in C++. I was wondering if someone wouldn't mind pointing out the source of my problem. :) The compile error I am getting is below and occurs in the RunProgram :: Run method definition error C2228: left of '.GetRunnersNameByIndex' must have class/struct/ union type error C2228: left of '.GetRaceTimePerRunnerByIndex' must have class/ struct/union type error C2228: left of '.GetEnvironmentalCoefficient' must have class/ struct/union type A code snippet is pasted below: Any help is appreciated! :) Cheers, Kush //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- class EnvironmentalFactors { private: Terrain CurrentTerrain; WeatherConditions CurrentWeather; double EnvironmentalCoefficient; void CalculateEnvironmentalCoefficient (void); public: EnvironmentalFactors(); double GetEnvironmentalCoefficient (void); }; EnvironmentalFactors :: EnvironmentalFactors(void) { this->CalculateEnvironmentalCoefficient(); } void EnvironmentalFactors ::CalculateEnvironmentalCoefficient (void) { this->EnvironmentalCoefficient = this- >CurrentTerrain.GetTerrainCoefficient() * this- >CurrentWeather.GetWeatherConditionsCoefficient(); } double EnvironmentalFactors ::GetEnvironmentalCoefficient (void) { return this->EnvironmentalCoefficient; } //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- class RaceCoordinator { private: Runner Runners[10]; double RaceTimeToScaleFactor; double CalculateRaceTimePerRunner(Runner); char* GetRunnersName (Runner); double GetRaceTimePerRunner(Runner); public: RaceCoordinator(void); char* GetRunnersNameByIndex(int); double GetRaceTimePerRunnerByIndex(int); }; RaceCoordinator::RaceCoordinator(void) { this->Runners[0].InitializeRunner("Mary", 22, 0.9); this->Runners[1].InitializeRunner("Joe", 34, 0.75); this->Runners[2].InitializeRunner("Nick", 30, 0.8); this->Runners[3].InitializeRunner("Tim", 19, 0.95); this->Runners[4].InitializeRunner("Suzy", 40, 0.6); this->Runners[5].InitializeRunner("Martha", 48, 0.6); this->Runners[6].InitializeRunner("Kris", 25, 0.8); this->Runners[7].InitializeRunner("Matt", 27, 0.5); this->Runners[8].InitializeRunner("Jerrod", 39, 0.65); this->Runners[9].InitializeRunner("James", 32, 0.85); this->RaceTimeToScaleFactor = 200; } double RaceCoordinator ::CalculateRaceTimePerRunner (Runner _Runner) { return (this->RaceTimeToScaleFactor) * _Runner.GetRunningCapability(); } double RaceCoordinator ::GetRaceTimePerRunner (Runner _Runner) { return this->CalculateRaceTimePerRunner(_Runner); } double RaceCoordinator ::GetRaceTimePerRunnerByIndex (int i) { return this->GetRaceTimePerRunner(this->Runners[i]); } char* RaceCoordinator ::GetRunnersName (Runner _Runner) { return _Runner.GetRunnersName(); } char* RaceCoordinator ::GetRunnersNameByIndex (int i) { return this->GetRunnersName(Runners[i]); } //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- class RunProgram { private: RaceCoordinator raceCoordinator(); EnvironmentalFactors raceEnvironmentalFactors(); public: RunProgram(); void Run(void); }; RunProgram::RunProgram(void) {} void RunProgram :: Run(void) { cout << "The race results are:" << endl; cout << "Name \t\t Time" << endl; for (int i = 0; i <= 9; ++i) { cout << this->raceCoordinator.GetRunnersNameByIndex(i) << "\t\t" << this->raceCoordinator.GetRaceTimePerRunnerByIndex(i) / this- >raceEnvironmentalFactors.GetEnvironmentalCoefficient() << endl; } } //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Ian Collins on 19 Jul 2008 16:26 Kush wrote: > Hello, > > I am attempting to create a small program to teach a colleague how to > program using C++ but I seem to be having my own difficulties with a > compile error. It has been quite some time since I last wrote code in > general, led alone in C++. > > I was wondering if someone wouldn't mind pointing out the source of my > problem. :) > > The compile error I am getting is below and occurs in the > RunProgram :: Run method definition > > error C2228: left of '.GetRunnersNameByIndex' must have class/struct/ > union type > error C2228: left of '.GetRaceTimePerRunnerByIndex' must have class/ > struct/union type > error C2228: left of '.GetEnvironmentalCoefficient' must have class/ > struct/union type > raceCoordinator (the bit on the left) is a function. -- Ian Collins. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Seungbeom Kim on 19 Jul 2008 16:22 Kush wrote: > The compile error I am getting is below and occurs in the > RunProgram :: Run method definition > > error C2228: left of '.GetRunnersNameByIndex' must have class/struct/ > union type > error C2228: left of '.GetRaceTimePerRunnerByIndex' must have class/ > struct/union type > error C2228: left of '.GetEnvironmentalCoefficient' must have class/ > struct/union type [snipped] > this->raceCoordinator.GetRunnersNameByIndex(i) > this->raceCoordinator.GetRaceTimePerRunnerByIndex(i) > this->raceEnvironmentalFactors.GetEnvironmentalCoefficient() raceCoordinator and raceEnvironmentalFactors are functions. You are applying Get...() member functions on the functions themselves, not the class objects returned from the function calls. Append pairs of parentheses '()' to get the results of the function calls, not the functions themselves. -- Seungbeom Kim [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: ppizzq on 19 Jul 2008 21:28 On 7?20?, ??3?22?, Seungbeom Kim <musip...(a)bawi.org> wrote: > Kush wrote: > > The compile error I am getting is below and occurs in the > > RunProgram :: Run method definition > > > error C2228: left of '.GetRunnersNameByIndex' must have class/struct/ > > union type > > error C2228: left of '.GetRaceTimePerRunnerByIndex' must have class/ > > struct/union type > > error C2228: left of '.GetEnvironmentalCoefficient' must have class/ > > struct/union type > > [snipped] > > > this->raceCoordinator.GetRunnersNameByIndex(i) > > this->raceCoordinator.GetRaceTimePerRunnerByIndex(i) > > this->raceEnvironmentalFactors.GetEnvironmentalCoefficient() > > raceCoordinator and raceEnvironmentalFactors are functions. You are > applying Get...() member functions on the functions themselves, not > the class objects returned from the function calls. Append pairs of > parentheses '()' to get the results of the function calls, not the > functions themselves. { Edits: quoted signature and clc++m banner removed, please don't quote them (the clc++m banner is appended to every article, including this one). -mod } in class RunProgram you define a memeber function named raceCoordinator without arguments and with RaceCoordinator type return value, not a member varible; you should write : private : RaceCoordinator raceCoordinator ; -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: ppizzq on 19 Jul 2008 22:28 this line is the error: private: RaceCoordinator raceCoordinator(); you define a function named raceCoordinator which has no arguments and return a RaceCoordinator value type; you should write : priviate : RaceCoordinator raceCoordinator; -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Next
|
Last
Pages: 1 2 Prev: Why is bitset defined in the associative containers section? Next: Suggestions on map template / Library |