Hello, i have a book that is teaching me the basics of c++

i understand most of it and its really fun, but i need some help creating my own applacation.

i want to create a class caled bandit and have a sub class scout
so that under bandits i can have scout artillary ect.

i also want these broken into seprate .h files like bandits.h and mines.h ect

my problem is calling the class in the .h file from my main.cpp file i get an error

C:\Cpp_Docs\Test\main.cpp `Bandit' undeclared (first use this function)

here is the code i have right now. i am just trying to be able to use the class in the main.cpp and still have the class in the .h file

Thanks BM


main.cpp

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

//Global

int main()
{
    Bandit *pScout = new Scout;
}

bandit.h

#include <iostream>

class Bandit
{
      public:
             Bandit(); // constructor
             ~Bandit(); // destructior
             //functions
             bool return_alive();
             int return_health();
             int return_armour();
             //generic 
             int health;
             int armour;
      private:
};
Bandit()
{
        std::cout<<"Bandit Constructed\n";

~Bandit()
{
         std::cout<<"Bandit Deconstructed\n";
}
bool return_alive()
{
     if (health > 0)
     {
                return true;
     }
     else
     {
         return false;
     }
}
int return_health()
{
    return health;
}
int retunr_armour()
{
    return armour;
}
class scout : public Bandit
{
      public:
             scout(); // constructer
             ~scout(); // destructer
             void set_speed(int Speed);
             void set_armour(int Armour);
             void set_health(int Health);
             void set_damage(int Damage);
             void set_hitChance(float HitChance);
      private:
              int speed;
              int armour;
              int health;
              int damage;
              float hitChance;
};
scout()
{
       std::cout<<"Scout created\n";
}
~scout();
{
         std::cout<<"Scout Destryed\n";
}
void set_speed(int Speed)
{
     speed = Speed;
}
void set_armour(int Armour)
{
     armour = Armour;
}
void set_health(int Health)
{
     health = Health;
}
void set_damage(int Damage)
{
     damage = Damage;
}
void set_hitChance(float HitChance)
{
     hitChance = HitChance;
}

Change #include "\\bandit.h" to #include "bandit.h" . That's more likely to be what your compiler is expecting. You also have a syntax error in the Bandit class' constructor definition.

thanks i fixed that i missed a } a noobish thing to do.

so i removed the \\

now i get

C:\Cpp_Docs\Test\main.cpp In file included from main.cpp

and then in my function i get this

C:\Cpp_Docs\Test\bandit.h expected unqualified-id before ')' token

then somthing about my destructor ?

C:\Cpp_Docs\Test\bandit.h destructors must be member functions

some help please BM

thanks to much persistance i figured this out!

thank you for you help Narue

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.