Error E2303 Type name expected?

Discussion in 'C++' started by Zenon, Nov 13, 2003.

  1. Zenon

    Zenon Guest

    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
    Zenon, Nov 13, 2003
    #1
    1. Advertising

  2. Zenon

    Amit Gulati Guest

    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" <> wrote in message
    news:...
    > 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
    Amit Gulati, Nov 13, 2003
    #2
    1. Advertising

  3. Zenon

    Rolf Magnus Guest

    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?
    Rolf Magnus, Nov 13, 2003
    #3
  4. Zenon

    Zenon Guest

    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" <> 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" <> wrote in message
    > news:...
    > > 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
    Zenon, Nov 13, 2003
    #4
  5. Zenon

    Rolf Magnus Guest

    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
    > {}
    Rolf Magnus, Nov 13, 2003
    #5
  6. Zenon

    Zenon Guest

    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 <> wrote in message news:<bovrt5$317$01$-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?
    Zenon, Nov 13, 2003
    #6
  7. Zenon

    Rolf Magnus Guest

    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.
    Rolf Magnus, Nov 13, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Edwards

    Type name expected: Errors

    Andrew Edwards, Jul 27, 2003, in forum: C++
    Replies:
    1
    Views:
    778
    Andrew Edwards
    Jul 27, 2003
  2. Sergei Gnezdov

    type* name vs. type *name

    Sergei Gnezdov, Mar 29, 2005, in forum: C Programming
    Replies:
    5
    Views:
    287
    Gordon Burditt
    Mar 29, 2005
  3. bubzilla
    Replies:
    2
    Views:
    923
    bubzilla
    Sep 25, 2006
  4. =?iso-8859-1?B?UG9pbmNhcuhf6F9hbmRhdG8=?=

    MALLOC: TYPE NAME EXPECTED

    =?iso-8859-1?B?UG9pbmNhcuhf6F9hbmRhdG8=?=, Nov 21, 2006, in forum: C Programming
    Replies:
    2
    Views:
    511
    =?iso-8859-1?B?UG9pbmNhcuhf6F9hbmRhdG8=?=
    Nov 21, 2006
  5. Replies:
    1
    Views:
    2,307
Loading...

Share This Page