Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

freeman-1387

macrumors newbie
Original poster
Jan 17, 2011
6
0
Hi everyone!
I need some problem. My XCODE project contained 'time.h' and 'string.h' files with my some classes.
In the compilation process, it became clear that my file has a higher priority compared to a standard "string.h" file. Why ?
Use #include<string>, including my "string.h" file.

with "time.h" idential situation.

how to fix it?
Thanks
 
Working as expected

I would actually say this isn't a problem so much as its an intended feature. It's never a good idea to name your projects the same as standard libraries unless you're trying to make your own custom version of them.
 
You could include them like this:
#include <string.h>
#include "string.h"

That would get the system string.h first, then yours.

Generally, though, it's a bad idea to name your files the same as system files. It makes it difficult for other people to read as they already know what string.h is supposed to mean, and can make debugging code more difficult. Plus you might inadvertently change the behaviour of something in the system string.h.

If you look at the beginning of /usr/include/string.h, you will see the lines:
#ifndef _STRING_H_
#define _STRING_H_

This is so you won't include the file more than once. All include files should have this when you start having multiple files including your include files.

These things become important when you start writing larger programs and working with other people.
 
Thanks for all!
I chose way of rename files, and it fix problem.
Hello from russia !
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.