草庐IT

main_template

全部标签

c++ - 解析参数到 main()

在C++中,是否存在用于解析main()函数参数的实用程序的完善、完整、开源的实现?我自己写的,我看到周围有很多其他人。但是我在想是否有更好的实现可用,它提供了相应可执行文件所期望的所有功能。 最佳答案 Boost提供了一个开源实现ProgramOptions. 关于c++-解析参数到main(),我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/9943566/

c++ - reference_wrapper : make_pair VS Class Template Argument Deduction (CTAD)

为什么make_pair和类模板参数推导(CTAD)不同意生成哪种类型?#include#include#include#includeintmain(){intmyInt=5;std::reference_wrappermyIntRef=myInt;automyPair=std::make_pair(myInt,myIntRef);std::pairMy2ndPair(myInt,myIntRef);std::cout输出:St4pairIiRiE//std::pairSt4pairIiSt17reference_wrapperIiEE//std::pair>更新:为什么std::p

c++ - 嵌套模板特化结果为 "Illegal use of explicit template arguments"?

如何专门化嵌套模板?(请参阅下面的错误。)usingstd::reverse_iterator;templatereverse_iteratormake_reverse_iterator(constIt&it){returnreverse_iterator(it);}templateItmake_reverse_iterator>(constreverse_iterator&it){//Above^//errorC2768://'make_reverse_iterator':illegaluseofexplicittemplateargumentsreturnit.base();}

c++ - 在每个源文件中替代 "extern template"

我正在开发一个库,其中我们的许多核心对象都是模板,其中一个特定实例以指向该模板实例的智能指针的形式出现在项目的大多数文件中。我在单个源文件中明确实例化了这些模板。我们最近切换到C++11,我正在尝试使用新的externtemplateclassMyTemplate;加快编译速度。我的第一个问题是我是否在周围使用智能指针MyTemplate正在隐式实例化模板并要求文件顶部的“外部模板..”以避免重复实例化。我的第二个问题是是否有一些替代方法来添加所有这些externtemplateclassMyTemplate;到每个源文件。为我定义的每个模板搜索智能指针的每个实例并确保我在该文件中有正

C++ : Check if the template type is one of the variadic template types

这个问题在这里已经有了答案:Checkifatypeispassedinvariadictemplateparameterpack(3个答案)关闭7年前。假设我们有函数:templatevoidfoo(){...};检查“Kind”类型是否是C++(包括C++1z)中的“Kinds”类型之一的最简单方法是什么?

c++ - std::map.insert "could not deduce template argument for..."

我正在尝试熟悉STL库,但我无法理解我的编译错误。我使用编译器错误字符串“无法推断...的模板参数”搜索了其他问题,但没有一个答案似乎适用或相关。Error4errorC2784:'boolstd::operator&,conststd::unique_ptr&)':couldnotdeducetemplateargumentfor'conststd::unique_ptr&'from'conststd::string'c:\programfiles(x86)\microsoftvisualstudio10.0\vc\include\xfunctional125我正在编写一个简单的解释

无法在 main 中访问在函数中初始化的 C++ 数组

我有一个用于在C++中初始化数组的函数。初始化后,main无法访问数组中的数据。不知道为什么。有帮助吗?voidtestArray(int*listPtr){listPtr=newint[2];listPtr[0]=0;listPtr[1]=1;}//endtestArrayvoidmain(){int*list;testArray(list);cout 最佳答案 这是因为指针是按值传递的。函数的参数被复制,函数的第一行用新表达式的结果替换指针的本地拷贝。返回main()的指针的原始拷贝不受此影响。您可以通过引用传递指针来“修复”此

c++ - 错误 LNK2019 未解析的外部符号 _WinMain@16 在函数 "int __cdecl invoke_main(void)"(?invoke_main@@YAHXZ) 中引用

这是我的剧本我不知道如何解决这个错误请帮我非常感谢floatangle=15;floatx,y,z;//forpolygonrotatevoiddisplay(){glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//clearscreenanddepthbufferglLoadIdentity();glPushMatrix();glColor3f(1.0,0.0,0.0);glBegin(GL_POLYGON);glVertex2f(160.0,360.0);glVertex2f(300.0,360.0);glVertex2f(160.

c++ - 为什么我不能将 std::unique_ptr 用作 "template<class> class"参数?

这段代码:#includetemplateclassPtr>classA{Ptrints;};usingB=A;产生以下错误(使用GCC6.3):a.cpp:6:28:error:type/valuemismatchatargument1intemplateparameterlistfor‘templateclassPtr>classA’usingB=A;^a.cpp:6:28:note:expectedatemplateoftype‘templateclassPtr’,got‘templateclassstd::unique_ptr’现在,我可以像这样解决这个问题:templateu

c++ - MI 和隐式复制构造函数错误(原为 : Under what conditions can a template be the copy constructor?)

我很确定这个问题的答案是,“模板永远不可能成为复制构造函数。”不幸的是,我只花了3个小时弄清楚为什么我会收到有关递归的警告,跟踪它到复制构造函数,看着调试器发疯,不让我看递归代码,最后跟踪到一个基础构造函数中缺少“&”。你看,我有一个复杂的基于策略的设计主机,它已经运行了一段时间了。我着手将两个策略合二为一并遇到了一个递归复制构造函数。将其缩小为一个策略,该策略需要提供一个构造函数,该构造函数可以采用一种XXX概念作为其参数,但在这种情况下,我只是放弃它。所以我写了structmy_policy{templatemy_polity(Tconst){}//missing'&'...oop