Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Getting the following errors and not sure why. My classes for Van are defined ju

ID: 3672728 • Letter: G

Question

Getting the following errors and not sure why. My classes for Van are defined just like for everything else. Also not sure why I am getting the error "undeclared identifier" . Below are the errors when I try and build:

______________________________________________________________________________________

./vehicles.h:1:2: error: unterminated conditional directive
#ifndef VEHICLES_H
^
vehicles.cpp:33:44: error: member initializer 'verbose_' does not name a non-static data member or base class
: serialNumber_(0), passengerCapacity_(0), verbose_(false)
                                           ^~~~~~~~~~~~~~~
vehicles.cpp:36:10: error: out-of-line definition of 'Vehicle' does not match any declaration in 'Vehicle'
Vehicle::Vehicle( const char *serialNumber, unsigned int passengerCapacity, bool verbose )
         ^~~~~~~
vehicles.cpp:37:60: error: member initializer 'verbose_' does not name a non-static data member or base class
: serialNumber_(0), passengerCapacity_(passengerCapacity), verbose_(verbose)
                                                           ^~~~~~~~~~~~~~~~~
vehicles.cpp:39:5: error: use of undeclared identifier 'verbose_'; did you mean 'verbose'?
if (verbose_) std::cout << "Vehicle() ";
    ^~~~~~~~
    verbose
vehicles.cpp:36:82: note: 'verbose' declared here
Vehicle::Vehicle( const char *serialNumber, unsigned int passengerCapacity, bool verbose )
                                                                                 ^
vehicles.cpp:51:5: error: use of undeclared identifier 'verbose_'
if (verbose_) std::cout << "~Vehicle() ";
    ^
vehicles.cpp:82:6: error: use of undeclared identifier 'verbose_'
{if (verbose_)std::cout << "Car() "; }
     ^
vehicles.cpp:87:5: error: use of undeclared identifier 'verbose_'
if (verbose_) std::cout << "Car() ";
    ^
vehicles.cpp:93:5: error: use of undeclared identifier 'verbose_'
if (verbose_) std::cout << "~Car() ";
    ^
vehicles.cpp:103:6: error: use of undeclared identifier 'verbose_'
{if (verbose_)std::cout << "Truck() ";}
     ^
vehicles.cpp:109:5: error: use of undeclared identifier 'verbose_'
if (verbose_) std::cout << "Truck() ";
    ^
vehicles.cpp:121:5: error: use of undeclared identifier 'verbose_'
if (verbose_) std::cout << "~Truck() ";
    ^
vehicles.cpp:145:1: error: use of undeclared identifier 'Van'
Van::Van()
^
vehicles.cpp:149:1: error: use of undeclared identifier 'Van'
Van::Van( const char *serialNumber, unsigned int passengerCapacity,
^
vehicles.cpp:157:1: error: use of undeclared identifier 'Van'
Van::~Van()
^
vehicles.cpp:157:7: error: expected the class name after '~' to name a destructor
Van::~Van()
      ^
vehicles.cpp:162:7: error: use of undeclared identifier 'Van'
float Van::LoadCapacity() const
      ^
vehicles.cpp:167:13: error: use of undeclared identifier 'Van'
const char *Van::ShortName() const
            ^
vehicles.cpp:172:1: error: use of undeclared identifier 'Tanker'
Tanker::Tanker()
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]    

_________________________________________________________________________________________

Here is my code:

(vehicles.h)

____________

#ifndef VEHICLES_H
#define VEHICLES_H

#include
#include

enum VehicleType { badSn, vehicle, car, truck, van, tanker, flatbed };

class Vehicle
{
public:
Vehicle(); // default constructor
Vehicle( const char *, unsigned int ); // 2-arg constructor
virtual ~Vehicle();
const char* SerialNumber() const; // returns serial number
unsigned int PassengerCapacity() const; //returns passenger capacity
virtual float LoadCapacity() const; // returns 0
virtual const char* ShortName() const; // returns "UNK"
virtual float Toll() const; // returns toll using fee schedule
static VehicleType SnDecode(const char* sn);
private:
char * serialNumber_;
unsigned int passengerCapacity_;
};

class Car : public Vehicle
{
public:
Car();
Car( const char *, unsigned int );
virtual ~Car();
const char* ShortName() const; // returns "CAR"
};

class Truck : public Vehicle
{
public:
Truck();
Truck( const char *, unsigned int, char * );
virtual ~Truck();
const char* ShortName() const; // returns "TRK"
float Toll() const; // returns toll using fee schedule
const char* DOTLicense() const; // returns the license no
virtual float LoadCapacity() const;
private:
char *DOTLicense_;
};                                

(vehicles.cpp)

______________

float Vehicle::LoadCapacity() const
{
return 0.0;
}

unsigned int Vehicle::PassengerCapacity() const
{
return passengerCapacity_;
}

const char *Vehicle::ShortName() const
{
return "UNK";
}

float Vehicle::Toll() const
{
return 2.00; // Non-Truck toll
}

Car::Car()
: Vehicle()
{if (verbose_)std::cout << "Car() "; }

Car::Car( const char *serialNumber, unsigned int passengerCapacity )
: Vehicle( serialNumber, passengerCapacity)
{
if (verbose_) std::cout << "Car() ";

}

Car::~Car()
{
if (verbose_) std::cout << "~Car() ";
}

const char *Car::ShortName() const
{
return "CAR";
}

Truck::Truck()
: Vehicle(), DOTLicense_(0)
{if (verbose_)std::cout << "Truck() ";}
                                        

Explanation / Answer

They most often come from forgetting to include the header file that contains the function definition, for example, this program will give an 'undeclared identifier' error:

Missing header

To fix it, we must include the header:

To read more, see http://msdn.microsoft.com/en-us/library/aa229215(v=vs.60).aspx.

Misspelled variable

Another common source of beginner's error occur when you misspelled a variable:

Incorrect scope

For example, this code would give an error, because you need to use std::string:

Use before declaration

g has not been declared before its first use. To fix it, either move the definition of g before f:

Or add a declaration of g before f:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote