草庐IT

template_directory

全部标签

c++ - template<class key, class type> 在 C++ 中的方法之前是什么意思?

我有这段代码,我试图理解遵循的约定,.cpp文件中定义的所有方法都有template写在他们面前。这是什么意思?例子://ConstructortemplateMyOperation::MyOperation(){//methodimplementation}//AmethodtemplateMyOperation::otherOperation(){//methodimplementation}谢谢 最佳答案 必须已经有一个很好的答案,但我也会把我的也扔进池中。C++允许程序结构的声明和实现分开进行。它源于C/C++程序员如何相互

C++ Templates 多态障碍

接口(interface):templateclassInterface{public:typedefTUnits;virtualTget()=0;};实现1:classImplementation1:publicInterface{public:floatget(){return0.0f;}};实现2:classImplementation2:publicInterface{public:intget(){return0;}};容器(有错误):classContainer{private:Interface*floatGetter;intn;Timer::Units*array;pu

c++ - 使用 `extern template` 防止模板类的隐式实例化

考虑以下代码片段:templatestructX{};externtemplatestructX;intmain(){X{};}它编译并链接:liveexampleongodbolt.org.由于externtemplate声明,我希望它不会链接。我的理解是externtemplate的意思是:“请不要在这个TU中实例化这个特定的模板特化,它将由其他一些TU提供,你可以链接到它”.示例/描述。我在isocpp上看到过,cppreference似乎验证了我的心智模型。例如Fromhttps://en.cppreference.com/w/cpp/language/class_templa

c++ - CMake 错误 : "add_subdirectory not given a binary directory"

我正在尝试将GoogleTest集成到更大项目的子项目中,但找不到令我满意的解决方案。我有两个约束:GoogleTest的源代码已经在项目结构中的某处(因此无法使用URL从git存储库下载它)GoogleTest的源代码不是我的子项目的子目录(永远不会)所以当我尝试做这样的事情时:add_subdirectory(${GOOGLETEST_PROJECT_LOCATION})我收到了:CMakeErroratunit_tests/CMakeLists.txt:10(add_subdirectory):add_subdirectorynotgivenabinarydirectorybut

c++ - 使用 `A<int>::template B<int> x;` 定义变量是否符合 C++ 标准?

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。gcc、vc++和clang接受以下代码。templatestructA{templatestructB{};};intmain(){A::By;//OKasexpectedA::templateBx;//AlsoOK!Isthisstandard-compliant?};使用A::templateBx;定义变量是否符合C++标准??

c++ - 使用 "template"编写 C 或 C++ 库

(1)。在使用C++模板时,编译器(如g++)不会直接编译模板定义(只能​​在头文件中,不能在源文件中),而是根据模板定义为它的每个实例生成代码,然后为它的实例编译生成的代码?(2)。如果我想编写一个提供模板类和模板函数的C++库,是否无法将库编译为共享文件(.so,.a),因为它们的实例化不会出现在库代码中的任何位置,而只会出现在用户程序?如果是,是否意味着模板库只是源代码文件而不是预编译文件?C++标准模板库(STL)是如何实现的?其源代码是预编译的还是与用户程序一起编译的?(3)。在C中,如何编写一个库来提供像C++中的模板函数一样的函数?重载是一个好的解决方案吗?如果我必须为不

c++ - 使用 Lambda/Template/SFINAE 自动化 try/catch-safeguarding trampoline 函数

我有100个左右的蹦床功能。我想知道是否可以自动将每个包装在try/catchblock中。请提前警告,这不是一个简单的问题。我将首先用(简化的)代码描述问题,然后在下面尝试尽可能地回答它,以便读者可以看到我的位置。Foo有一个函数指针表:编辑:这是一个C函数指针表。所以它可以接受staticW::w。签名在这里:http://svn.python.org/projects/python/trunk/Include/object.h编辑:我尝试了一个测试用例here:classFoo{Tabletable;Foo(){//Eachslothasadefaultlambda.:table

c++ - CMAKE include_directories

我正在尝试将我的图书馆与其他图书馆链接起来lib1使用CMAKE2.8.应该说是在Windows上。在CMakeLists.txt我有:add_library(mylib${sources})include_directories(${CMAKE_SOURCE_DIR}/lib1/include)target_link_libraries(mylib${lib1_path})但是编译器说一些#include在我的库中未解决,可能是因为没有-I.../lib1/includegcc的命令行参数.更新:应该说编译器在编译测试而不是mylib时提示. 最佳答案

c++ - 为什么此代码会出现错误 "template specialization requires ' template< >'"?

当我尝试用Clang编译它时templatestructField{charconst*name;Field(charconst*name):name(name){}};templateclassCRTP{staticFieldconst_field;};classClass:publicCRTP{};FieldconstCRTP::_field("blah");intmain(){}我明白了error:templatespecializationrequires'template'FieldconstCRTP::_field("blah");~~~~~~~~~~~^我根本不明白这个错

c++ - Qt 5.3。 QtWidgets : No such file or directory #include <QtWidgets>

我想编译Qt例子。我收到错误QtWidgets:Nosuchfileordirectory#includegreaterThan(QT_MAJOR_VERSION,4):QT+=widgets-doesnothelpQT+=widgets-doesnothelpINCLUDEPATH+=/opt/Qt/5.3/Src/qtbase/include/-doesnothelpQt5.3。Ubuntu14.04x64。 最佳答案 您需要仔细检查您是否完成了所有这些步骤:已安装模块greaterThan(QT_MAJOR_VERSION,4