Oct 17, 2009 at 2:58am UTC
I keep getting this error when I try to compile: error: expected primary-expression before "double"
The line I get the error on is at the bottom of this email. Any help would be greatly appreciated.
Here is the source header:
#ifndef MYARMYHEAD_H_INCLUDED
#define MYARMYHEAD_H_INCLUDED
using namespace std;
class Army
{
public:
double kills;
enum rating {raw, trained, seasoned, veteran, elite};
public:
double soldiers;
rating Soldier_rating;
public:
double Get_Kills();
void Set_Kills(double);
double Get_Soldiers();
string Get_Rating();
int Get_Rating(int);
int Up_Rating();
// Army(double, rating);
Army(double, Army::rating Soldier_rating);
};
class ArmyX : public Army
{
public:
double grunt_soldiers;
rating grunt_rating;
double nco_soldiers;
rating nco_rating;
double officer_soldiers;
rating officer_rating;
double general_soldiers;
rating general_rating;
double leader_soldier;
rating leader_rating;
// double Get_SoldierTyp(int);
ArmyX(double, Army::rating Soldier_rating, double);
};
#endif // MYARMYHEAD_H_INCLUDED
Here is the .cpp
#include <iostream>
#include "MyArmyHead.h"
double Army::Get_Kills (){
return kills;
}
void Army::Set_Kills (double kills){
this->kills=kills;
soldiers-=kills;
}
double Army::Get_Soldiers (){
return soldiers;
}
int Army::Get_Rating (int ){
return Soldier_rating;
}
string Army::Get_Rating (){
switch (Soldier_rating)
{
case 0:
return "raw";
case 1:
return "trained";
case 2:
return "seasoned";
case 3:
return "veteran";
case 4:
return "elite";
default:
return "unknown";
}
}
int Army::Up_Rating (){
switch (Soldier_rating)
{
case 0:
Soldier_rating=trained;
break;
case 1:
Soldier_rating=seasoned;
break;
case 2:
Soldier_rating=veteran;
break;
case 3:
Soldier_rating=elite;
break;
default:
return (1);
}
return(0);
}
Army::Army(double size, rating rate)
{
this->kills=0;
this->soldiers=size;
this->Soldier_rating=rate;
}
HERE IS WHERE I GET THE ERROR
ArmyX::ArmyX(double size, rating rate, double grunt) : Army(double size, rating rate)
{
grunt_soldiers=grunt;
}
Oct 17, 2009 at 4:02am UTC
First, please post your code with proper tags. It's way to hard to read it this way.
Now, I am not sure what you are trying to do in this line
ArmyX::ArmyX(double size, rating rate, double grunt) : Army(double size, rating rate)
If you are trying to use initializer list, then correct syntax will be
ArmyX(double size, rating rate, double grunt) : data_member(size), data_member(rate), data_member(grunt)
where data_member is the name of the member you are trying to initialize
Last edited on Oct 17, 2009 at 4:04am UTC
Oct 17, 2009 at 10:54am UTC
You can call a parent constructor, but it's a function so you need to remove the type specifiers:
ArmyX::ArmyX(double size, rating rate, double grunt) : Army( size, rate)
Oct 17, 2009 at 3:24pm UTC
Thanks Bazzy and kevinchkin, it worked by eliminating the type specifiers in the base class.
I apoligize for posting the problem without tags, but I'm trying to figure out how to cut and paste the source "as-is" from my IDE. I'm using codeblocks if that makes a difference.
Also (I hope this is not off topic) I just had verison fios service installed, and the verizon guy messed with my computer and now my IDE seems different "fuzzy"?
Thanks again
Oct 17, 2009 at 3:42pm UTC
I'm trying to figure out how to cut and paste the source "as-is" from my IDE
Put your code inside [co
de][/code] tags, it will highlight C++ syntax ( click on the # button on the right of the edit box )
I just had verison fios service installed, and the verizon guy messed with my computer and now my IDE seems different "fuzzy"?
Try reinstalling your IDE
Last edited on Oct 17, 2009 at 3:42pm UTC