Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Error E2303 Type name expected?

Reply
Thread Tools

Error E2303 Type name expected?

 
 
Zenon
Guest
Posts: n/a
 
      11-13-2003
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
 
Reply With Quote
 
 
 
 
Amit Gulati
Guest
Posts: n/a
 
      11-13-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      11-13-2003
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?

 
Reply With Quote
 
Zenon
Guest
Posts: n/a
 
      11-13-2003
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" <(E-Mail Removed)> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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

 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      11-13-2003
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
> {}


 
Reply With Quote
 
Zenon
Guest
Posts: n/a
 
      11-13-2003
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 <(E-Mail Removed)> wrote in message news:<bovrt5$317$01$(E-Mail Removed)-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?

 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      11-13-2003
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL Type Mismatch error indexed name returns a value whose type does not match programmingzeal VHDL 0 05-06-2012 06:38 AM
Compiler error dependent name is not a type prefix with 'typename' toindicate a type Sanil C++ 2 12-14-2007 09:14 AM
Compilation Error:Class name does not name a type. sharat C++ 13 04-19-2007 10:50 AM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
type* name vs. type *name Sergei Gnezdov C Programming 5 03-29-2005 06:04 PM



Advertisments