Well, in C++, if you're going to inherit from an object, that objec type must exist. Your code does not define any object named TObject, so you cannot inherit from it. This is a really important point.
1 2 3 4 5 6 7
|
class Bot : public TObject {
public:
struct bot{
int money;
int rank;
char* name;
};
| |
This is something of a mess. So you're trying to define a class (which in C++ is the same as a struct, except for default privacy) and then inside it you immediately define another class, with almost the same name?
This is what I think you were aiming for.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#ifndef BOTS_H_INCLUDED
#define BOTS_H_INCLUDED
class bot {
public:
int money;
int rank;
char* name;
bot BotTrue();
bot BotFalse();
bot BotInitialise(char* name);
int BotRank();
void BotPrint();
};
#endif // BOTS_H_INCLUDED
| |
bot botA;
Creating an instance of an object in a header is not necessarily a bad idea, but in this code, it seems a bit off, and trying to create this instance of an object in the middle of a class definition makes no sense (it would mean that your bot object contained another bot, but that bot would be a complete bot that contained
another bot, but that bot object would
also contain another bot etc etc, like Russian dolls to infinity - this is clearly not going to work).
Your functions are almost all defined in the bots.h file, and then you define them again (differently!) in whatever that third file is. This is bad. Define them once. Make sure you know the difference between definition and declaration.
There are lots more problems in this code. Fundamentally, I think you've tried something far too big for your current level of expertise. That you tried to fix it by sticking in
: public TObject
because you saw that somewhere on the internet is a big clue that you don't understand inheritance. There is no need for inheritance in this class, so just don't do it.
I see that in many of your functions (which, being class functions, happen inside an already existing bot object) you create a whole new bot, which you then alter and then return. This demonstrates a fundamental misunderstanding of what classes are for and how class functions work.
You need to start with a very simple class definition and get that working, and then add pieces one at a time. Here's a start:
1 2 3 4 5 6 7 8 9
|
class bot{
public:
int money;
void BotInitialise()
{
money =0;
}
};
| |
In C++, we tend to not use specific initialisation functions like this, because we have constructor functions. It's worth learning about them too.