By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

Error E2303 Type name expected?

P: n/a
Folks,
I cannot figure out why I am getting an error: Error E2303 EngineX.hpp
19: Type name expected. Here is my code. Can you please help?

#ifndef EngineX__hpp
#define EngineX__hpp

#include<iostream>
#include <cstring>
#include <cmath>
#include <sstream>
#include <fstream>

class EngineX : public Engine
{
// Define data members
int horsepower;

// define function prototypes
public:

EngineX(int hp); // Constructor with hp input
~EngineX();// Destructor
std::string name(); // returns engine name
double torque(double rpm, double fuelRate);// returns engine torque
};
#endif

#include <cstring>
#include <cmath>
#include<iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <sstream>
#include "EngineX.hpp"

using namespace std;

EngineX::EngineX(int hp) // Constructor with hp input
{
horsepower = hp;
}

EngineX::~EngineX()// Destructor
{}

string EngineX::name() // returns engine name
{
stringstream ss;
ss << horsepower;
string b(ss.str());
return ("EngineX " + b + "HP");
}

double torque(double rpm, double fuelRate) // returns engine torque
{
double lrpmx = 0;
double engineTorque = 0;
double torque = 0;
lrpmx = rpm / 1000;
torque = ((-130*lrpmx*lrpmx*lrpmx) + (-600*lrpmx*lrpmx) - (791 *
lrpmx) + 2);
engineTorque = fuelRate*torque;
return engineTorque;
}
thanks very much,

Zenon
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
since EngineX is a subclass of Engine the compiler needs to know about
Engine??
You probably need to include the header file that has Engine class
declaration.

"Zenon" <ze****@comcast.net> wrote in message
news:b1*************************@posting.google.co m...
Folks,
I cannot figure out why I am getting an error: Error E2303 EngineX.hpp
19: Type name expected. Here is my code. Can you please help?

#ifndef EngineX__hpp
#define EngineX__hpp

#include<iostream>
#include <cstring>
#include <cmath>
#include <sstream>
#include <fstream>

class EngineX : public Engine
{
// Define data members
int horsepower;

// define function prototypes
public:

EngineX(int hp); // Constructor with hp input
~EngineX();// Destructor
std::string name(); // returns engine name
double torque(double rpm, double fuelRate);// returns engine torque
};
#endif

#include <cstring>
#include <cmath>
#include<iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <sstream>
#include "EngineX.hpp"

using namespace std;

EngineX::EngineX(int hp) // Constructor with hp input
{
horsepower = hp;
}

EngineX::~EngineX()// Destructor
{}

string EngineX::name() // returns engine name
{
stringstream ss;
ss << horsepower;
string b(ss.str());
return ("EngineX " + b + "HP");
}

double torque(double rpm, double fuelRate) // returns engine torque
{
double lrpmx = 0;
double engineTorque = 0;
double torque = 0;
lrpmx = rpm / 1000;
torque = ((-130*lrpmx*lrpmx*lrpmx) + (-600*lrpmx*lrpmx) - (791 *
lrpmx) + 2);
engineTorque = fuelRate*torque;
return engineTorque;
}
thanks very much,

Zenon

Jul 19 '05 #2

P: n/a
Zenon wrote:
Folks,
I cannot figure out why I am getting an error: Error E2303 EngineX.hpp
19: Type name expected. Here is my code. Can you please help?

#ifndef EngineX__hpp
#define EngineX__hpp

#include<iostream>
#include <cstring>
#include <cmath>
#include <sstream>
#include <fstream>

class EngineX : public Engine


You didn't #inlude the header file that contains the definition for the
Engine class, so how is the compiler supposed to know about it?

Jul 19 '05 #3

P: n/a
Thanks, that makes sense. Do I just add an #include"Engine.cpp" right
after the #include "EngineX.hpp" statement? My engine file is
included below

#include<iostream>
#include <cstring>
#include <cmath>
#include <sstream>
#include <fstream>

class Engine
{
// define function prototypes
public:
// Engine(); // Default constructor
virtual ~Engine() = 0; // Destructor
virtual std::string name() = 0;// returns engine name
virtual double torque(double rpm, double fuelRate) = 0; // returns
engine torque

};

Engine::~Engine()// Destructor
{}
"Amit Gulati" <am********@cox.net> wrote in message news:<JGEsb.845$HD3.770@lakeread06>...
since EngineX is a subclass of Engine the compiler needs to know about
Engine??
You probably need to include the header file that has Engine class
declaration.

"Zenon" <ze****@comcast.net> wrote in message
news:b1*************************@posting.google.co m...
Folks,
I cannot figure out why I am getting an error: Error E2303 EngineX.hpp
19: Type name expected. Here is my code. Can you please help?

#ifndef EngineX__hpp
#define EngineX__hpp

#include<iostream>
#include <cstring>
#include <cmath>
#include <sstream>
#include <fstream>

class EngineX : public Engine
{
// Define data members
int horsepower;

// define function prototypes
public:

EngineX(int hp); // Constructor with hp input
~EngineX();// Destructor
std::string name(); // returns engine name
double torque(double rpm, double fuelRate);// returns engine torque
};
#endif

#include <cstring>
#include <cmath>
#include<iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <sstream>
#include "EngineX.hpp"

using namespace std;

EngineX::EngineX(int hp) // Constructor with hp input
{
horsepower = hp;
}

EngineX::~EngineX()// Destructor
{}

string EngineX::name() // returns engine name
{
stringstream ss;
ss << horsepower;
string b(ss.str());
return ("EngineX " + b + "HP");
}

double torque(double rpm, double fuelRate) // returns engine torque
{
double lrpmx = 0;
double engineTorque = 0;
double torque = 0;
lrpmx = rpm / 1000;
torque = ((-130*lrpmx*lrpmx*lrpmx) + (-600*lrpmx*lrpmx) - (791 *
lrpmx) + 2);
engineTorque = fuelRate*torque;
return engineTorque;
}
thanks very much,

Zenon

Jul 19 '05 #4

P: n/a
Zenon wrote:
Thanks, that makes sense. Do I just add an #include"Engine.cpp" right
after the #include "EngineX.hpp" statement?
No. You #include "Engine.hpp" at the beginning of "EngineX.hpp".

My engine file is
included below

#include<iostream>
#include <cstring>
#include <cmath>
#include <sstream>
#include <fstream>
Do you really need anything from that in your header?
class Engine
{
// define function prototypes
public:
// Engine(); // Default constructor
virtual ~Engine() = 0; // Destructor
virtual std::string name() = 0;// returns engine name
virtual double torque(double rpm, double fuelRate) = 0; // returns
engine torque

};

Engine::~Engine()// Destructor
{}


Jul 19 '05 #5

P: n/a
My assumption (and I am obviously a newbie) was that the inheritence
of Engine by EngineX in the lclass definition
class EngineX : public Engine
was the mechanism for this. Now since I don't have a header file for
the base class Engine, how do I go about including it? Must I have a
header file? Thank you very much for your help.

Rolf Magnus <ra******@t-online.de> wrote in message news:<bo*************@news.t-online.com>...
Zenon wrote:
Folks,
I cannot figure out why I am getting an error: Error E2303 EngineX.hpp
19: Type name expected. Here is my code. Can you please help?

#ifndef EngineX__hpp
#define EngineX__hpp

#include<iostream>
#include <cstring>
#include <cmath>
#include <sstream>
#include <fstream>

class EngineX : public Engine


You didn't #inlude the header file that contains the definition for the
Engine class, so how is the compiler supposed to know about it?

Jul 19 '05 #6

P: n/a
Please don't top-post. Put your answers below the text you're referring
to. This is not jeopardy, where we get the answer before the
question ;-)

Zenon wrote:
You didn't #inlude the header file that contains the definition for
the Engine class, so how is the compiler supposed to know about it?
My assumption (and I am obviously a newbie) was that the inheritence
of Engine by EngineX in the lclass definition class EngineX : public
Engine was the mechanism for this.


If there is no Engine class, how could deriving EngineX from it work?
Now since I don't have a header file for the base class Engine, how do
I go about including it?
Where do you have that base class defined then?
Must I have a header file?


Well, your class Enigne must be fully known to the compiler at the point
where you define EngineX. Usually, this is done by #including a header
that contains the definition of the base class.

Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.