Re: Problem when defining my own string.h
On Fri, 29 Feb 2008 12:13:48 -0800 (PST), sip.address@gmail.com wrote:
Your comment made me try a bit more when I was losing hope. I finally
found the problem I think. As you said, I made a small little project
with 3 files: main.cpp, string.cpp and string.h. When these files are
in the same folder, there's no problem. *But*, if I organize things a
bit, separating headers from source files into separate folders (like
using \inc and \src) then the problem appears again.
IME, there is no problem with this, even when you organize things.
So it seems that using "" is ok for header files in the same directory
as the source file, *but* if header files are in different
directories, then the system include directories have precedence over
the ones defined by /I parameter, which is certainly a pity, as I'd
have expected the ones defined by /D to be used first in such case.
In VC++, the only difference between "" and <> is that the former starts
the search in the directory containing the file making the #include. For
the detailed rules, see:
http://msdn2.microsoft.com/en-us/library/36k2cdd4(VS.71).aspx
Anyway as a workaround, I think I'll use inline methods for windows
builds, and maybe usual methods in other cases. This way the problem
shouldn't appear with MSVC at least.
Cheers.
PS: If anyone cares, here are the files I used. You can just create a
project/solution with these. If the files are in the same folder, it
will work, but if you use a tree structure (\inc, \src) it won't.
-- String.h --
#ifndef STRING_H_
#define STRING_H_
#include <string>
namespace System {
class String
{
public:
String();
~String();
private:
std::string mString;
};
}
#endif // STRING_H_
-- String.cpp --
#include "String.h"
namespace System {
String::String()
{}
String::~String()
{}
}
-- test.cpp --
#include "String.h"
int main()
{
System::String str("Hello");
return 0;
}
Again, there's not enough detail to tell what you're doing when it fails.
You need to state which directories contain which files and give the
command line you're using.
--
Doug Harrison
Visual C++ MVP