首页 > TAG信息列表 > template-function

c – 为什么模板函数不能将指向派生类的指针解析为指向基类的指针

编译器在编译时是否无法获取指向派生类的指针并知道它有一个基类?看来它不能,基于以下测试.请在最后查看我发表问题的评论. 我怎样才能让它发挥作用? std::string nonSpecStr = "non specialized func"; std::string const specStr = "specialized func"; std::string const nonTemp

c – 为什么没有模板函数比模板函数更多二进制

看到这个简单的程序 #include <cstdio> #include <cstdlib> void foo(){ printf("%d",1); } int main(){ foo(); } 我用linux上的gcc 4.6.4 -std = c 0x -O2 -g -Wall编译它. 和二进制文件11`238字节. 但是这段代码产生了11个150字节: #include <cstdio> #include <cstdlib>

c – Pimpl习语实现取决于模板函数

请考虑以下代码. template参数是一个必须提供函数bar()的处理程序类. 我正在使用Pimpl成语来隐藏Foo的实现细节.在拥有模板参数之前,构造函数定义在foo.cpp中,并且一切都很好. /////////// // foo.h /////////// class Foo { public: template <class Handler> F

c – 模板功能实例化的可移植性问题

我正在将一个项目从MSVC移植到Borland C,我遇到了模板功能的困难.例如,以下内容 void fn(const char *buffer) { vector<string> output; boost::split(output, string(buffer), is_any_of(",")); // ... 导致编译器错误: [BCC32 Error] example.cpp(208): E2285 Could not