Reputation: 173
I'm programming in c++ for gta mods. Therefore I use ScriptHook V.
In types.h there is this:
typedef DWORD Void;
typedef DWORD Any;
typedef DWORD uint;
typedef DWORD Hash;
typedef int Entity;
typedef int Player;
typedef int FireId;
typedef int Ped;
typedef int Vehicle;
typedef int Cam;
typedef int CarGenerator;
typedef int Group;
typedef int Train;
typedef int Pickup;
typedef int Object;
typedef int Weapon;
typedef int Interior;
typedef int Blip;
typedef int Texture;
typedef int TextureDict;
typedef int CoverPoint;
typedef int Camera;
typedef int TaskSequence;
typedef int ColourIndex;
typedef int Sphere;
typedef int ScrHandle;
And the natives.h uses this types:
namespace PLAYER
{
static Ped GET_PLAYER_PED(Player player) { return invoke<Ped> (0x43A66C31C68491C0, player); } // 0x43A66C31C68491C0 0x6E31E993
static Ped GET_PLAYER_PED_SCRIPT_INDEX(Player player) { return invoke<Ped>(0x50FAC3A3E030A6E1, player); } // 0x50FAC3A3E030A6E1 0x6AC64990
...
Now I wanted to make a Player class. But keep getting naming conflicts and I can't find a good solution to resolve them other then renaming my classes. Is there another way? My classes are in a namespace but it keeps conflicting.
Upvotes: 1
Views: 754
Reputation: 1725
You probably meant typedef DWORD Uint;
not typedef DWORD uint;
as the latter might cause name conflict with a common typedef in Posix's sys/types.h
.
Upvotes: 0
Reputation: 28659
There are 2 possible solutions to this.
Both solutions require you to put your code in its own namespace, as it is these namespaces that we have to use to resolve the ambiguity.
In the following examples I've chosen to call the namespace you'd put your own code in MyCode
- you're free to use any namespace you want, so long as it's unique.
Solution 1:
namespace Type
{
typedef int Player;
}
namespace MyCode
{
class Player
{
Player(Type::Player id); // here you specify the namespace "Type"
};
}
Solution 2:
If your typedefs have to be in the global namespace, then the scope resolution operator can be used to differentiate them
typedef int Player;
namespace MyCode
{
class Player
{
Player(::Player id); // here "::Player" refers to the typedef
};
}
See this SO answer for more information on the scope resolution operator
Upvotes: 2