Skip to main content
gamedev.net
🔒 Locked

Include problem with String.h

Started by LowRad0 4 replies 1k views
Original Post
LowRad0
LowRad0
Hi all! I'm using C++ for this... I'm trying to make a wrapper class for string operation that look more like the .NET equivalent. The problem is simple, i have named my file string.h and that causes errors when i include windows.h, since windows.h use the standard c++ string.h file. I want to know if there is a workaround for this?! Thanks, Jonathan
Servant of the Lord
Servant of the Lord
Quote:
Original post by LowRad0
Hi all!

I'm using C++ for this... I'm trying to make a wrapper class for string operation that look more like the .NET equivalent.

The problem is simple, i have named my file string.h and that causes errors when i include windows.h, since windows.h use the standard c++ string.h file.

I want to know if there is a workaround for this?!

Thanks,
Jonathan


Why not name yours 'String.h' or 'MyString.h'?
LowRad
LowRad
Since it is for a framework... i would like to name it the way it suppose to be. =)

If i need to, i'll change the name but i dont want to do that until im 100% sure there's no other way around.

Thanks!

Note: I forgot to say, this file is in a separate dll (the framework).
Daaark
Daaark
string.h is a standard c header that is included with every compiler. You have 'string.h' and 'cstring' in your include folder. This is going to cause nothing but conflicts.

If you are not going to distribute it, and use it only for yourself, you can include it with quotes and not '<>' #include "string.h". This will search your custom folders for the file first, instead of grabbing the one in the include folder first.

If you are going to distribute this file for others to use, rename it to something more fitting like 'libname_str.h', or you will end up causing headaches for some of your users.
LowRad
LowRad
Thanks for the reply...

I was hoping for a super magic precompiler statement ;)

I'll change the name then,
Jonathan
Paulius Maruska
Paulius Maruska
Or... You can put it in some subdirectory, like this:

#include <string.h> // includes standard library header#include <game/string.h> // includes something else


I use this approach all the time. Avoiding name conflicts like yours. I allways organize my source tree so that all public headers are in $(ProjectDir)\include\$(ProjectName)\ directory. This allows me to easily use the library (by simply adding include directory to INCLUDE env var).

Hope this helps.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.