Chr*_*vic 1 c++ file-io std stdio shadowing
我正在写一个游戏,现在我能够通过类及其方法实现文件系统sqlite.为了让生活更容易我已经打算写像一些功能fopen,fclose,fread,rename,等能够影子基础功能,并直接把我的给我的文件系统调用,而不是原来的一个.对于前三个功能,一切都适合我使用这些原型:
File *fopen(String _Filename, String _Mode); // i have my own optimized File struct
void fclose(File *_File);
size_t fread(String *_DstBuf, size_t _ElementSize, size_t _Count, File *_File);
这工作正常,因为我要么返回另一个结构或参数除了a File*而不是a FILE*,但重命名函数似乎有点棘手!
int rename(String _OldFilename, String _NewFilename);
这几乎是相同的原型.除了我使用std::string(typedef'ed String)比const char*!知道我怎么能说服我的编译器使用我的函数或忽略stdio-one?
你不能简单地使用任何其他名称的自己的函数是什么原因?
如果整个冲突与重载决策有关,那么你应该只是掩盖实际的原型; 您可以将它们转发到您自己的功能.
但是,我建议不要使用这里的一般方法:即使使用"修复",您最好还是包括订购问题,甚至可能包含重复的链接符号.
如果您的功能不相同,请使用其他名称.由于你使用的是c ++,你可以在MyFsFunctions.h中做这个恶意技巧(否则是不明智的):
namespace MyFsFunctions
{
// prototypes for fopen, fclose, fwrite, fread etc
}
using namespace MyFsFunctions;
// or:
using MyFsFunctions::fopen;
using MyFsFunctions::fclose;
using MyFsFunctions::fread;
using MyFsFunctions::fwrite; // etc...
Run Code Online (Sandbox Code Playgroud)
我很确定你仍然希望(需要)隐藏确切的函数原型(或者编译器可能仍会抱怨模糊的标识符引用).
其他提示: