Error E2303 Type name expected?

Z

Zenon

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
 
A

Amit Gulati

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.
 
R

Rolf Magnus

Zenon said:
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?
 
Z

Zenon

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
{}
 
R

Rolf Magnus

Zenon said:
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?
 
Z

Zenon

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.
 
R

Rolf Magnus

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 ;-)
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top