0

im trying to write a car class which has a class called "engine" in it i have a problem creating an instance of an engine (named it "myengine") *the error code says that i have unresolved externals i would appreciate any kind of help/commentary

    **this is the car header**

    #include "engine.h"
    #ifndef _car_
    #define _car_





     class car
    {
        engine myengine;                      //here is the error
        char* brandname="mybrand";
        char* model="mymodel";



    };




    #endif

**this is the engine header**


#ifndef _engine_
#define _engine_

class engine
{
public:

    float volume;
    float currentfuel;
    float maxfuel;
    bool activated;     //off
    engine();
     engine(float volume, float currentfuel, float maxfuel, bool activated) { 10, 0, 100, 0; }
    ~engine();
    void setfuel(float fuel);
    float getfuel();
    float getmaxfuel();
    void setmaxfuel(float maxfuel);
    float getvolume();
    void setvolume(float volume);
    void setactivated(bool active);
    bool getactivated();
    void activate(bool active);





};


#endif

**this is the engine cpp**

#include "engine.h"
#include <iostream>
using namespace std;

void engine::setfuel(float fuel)
{
    cout<<"enter fuel amount"<<endl;
    cin >> fuel;

    if (fuel < 0)
    {
        cout << "the amount of fuel cannot be less than 0";
    }
    else fuel = currentfuel;



}
Leo
  • 31
  • 1
  • 5
  • I could have translated the error message for you, if you had included it. – Neil Kirk Nov 08 '15 at 20:11
  • Severity Code Description Project File Line Error LNK2019 unresolved external symbol "public: __thiscall engine::engine(void)" (??0engine@@QAE@XZ) referenced in function "public: __thiscall car::car(void)" (??0car@@QAE@XZ) ConsoleApplication3 C:\Users\leoomri\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.obj 1 Severity Code Description Project File Line Error LNK1120 2 unresolved externals ConsoleApplication3 C:\Users\leoomri\Documents\Visual Studio 2015\Projects\ConsoleApplication3\Debug\ConsoleApplication3.exe 1 – Leo Nov 08 '15 at 22:57
  • Severity Code Description Project File Line Error LNK2019 unresolved external symbol "public: __thiscall engine::~engine(void)" (??1engine@@QAE@XZ) referenced in function "public: __thiscall car::~car(void)" (??1car@@QAE@XZ) ConsoleApplication3 C:\Users\leoomri\Documents\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.obj 1 – Leo Nov 08 '15 at 22:58
  • It tells you `engine::engine(void)` is missing, aka `engine`'s constructor. Where is it defined? – Neil Kirk Nov 08 '15 at 23:44
  • engine(float volume, float currentfuel, float maxfuel, bool activated) { 10, 0, 100, 0; } //constructor in engine.h – Leo Nov 09 '15 at 21:22
  • `engine::engine(void)` is the default constructor that takes no parameters. Also `10, 0, 100, 0;` doesn't do anything. – Neil Kirk Nov 10 '15 at 00:45
  • i should probably take a few steps back then thanks, Neil – Leo Nov 10 '15 at 10:08

0 Answers0