草庐IT

reference-type

全部标签

c++ - CLion "Instantiating an unknown structure without reference"但编译正常

我一直在尝试使用CLion编辑器和MinGW在Windows10(64位)上使用HDF5设置我的cmake项目。经过大量时间尝试正确设置我的CMakeLists文件后,我得到了一些工作-代码编译,mingw32-make或cmake没有错误。但是,我仍然在CLion中遇到带有红色下划线的错误,这些错误似乎对构建没有任何影响,但我感觉它们存在是因为我做错了什么。(除了使用C++进行类项目外,我还很陌生)这是我的CMakeLists.txtcmake_minimum_required(VERSION2.8)project(testProject)add_definitions(-std=c

C++ 调试窗口显示“<incomplete type> for string variable

据我所知,我正在以一种相当正常的方式初始化一个字符串,当我调试时,我的IDE(CLion)中的变量窗口将其值显示为.我有一些简单的代码导致字符串变量Bob出现问题.#includeintmain(){std::stringBob="thisdoesn'tshowupinthevariableswindow";std::cout我不知道它有什么影响,但我会包含CMakeLists文件,它似乎是我可以使用的最简单的文件。cmake_minimum_required(VERSION3.8)project(testing123)set(CMAKE_CXX_FLAGS"${CMAKE_CXX_F

c++ - 对非成员函数的 undefined reference - C++

我在头文件中有以下内容。namespacesilc{classpattern_token_map{/*Contents*/};pattern_token_map*load_from_file(constchar*);}在CPP文件中(这有适当的包含)pattern_token_map*load_from_file(constchar*filename){//Implementationgoeshere}在另一个CPP文件中。这已经包含了所有正确的内容。voidsome_method(){constchar*filename="sample.xml";pattern_token_map*

c++ - 迭代器模式 - 错误 C2679 : binary '<<' : no operator found which takes a right-hand operand of type 'std::string'

这个问题在这里已经有了答案:errorC2679:binary'(1个回答)关闭5年前。我正在尝试使用迭代器模式进行迭代和打印,但出现错误这里是错误:errorC2679:binary'couldbe'std::basic_ostream&std::operator>(std::basic_ostream&,constchar*)'这是错误的来源std::coutgetName();#ifndef_ROBOT1_#define_ROBOT1_namespaceguitars{namespaceComposite{namespaceInventoryParts{usingnamespac

c++ - 练习 : pointers and references in C++

这是正确的吗:a)指向一个字符的指针p1:char*p1;b)指向char的常量指针p2:char*constp2;c)指向常量char的指针p3:constchar*p3;d)指向常量char的常量指针p4:constchar*constp4;e)对char的引用r1:char&r1;f)对常量char的引用r2:constchar&r2;如果有任何错误,请告知我好吗? 最佳答案 他们都是对的。我看不到任何错误:-) 关于c++-练习:pointersandreferencesinC+

c++ - 为什么隐含的 "lambda to function pointer conversion"禁止静态成员的 "by reference"捕获?

C++11标准说(或者至少,我拥有的版本——不是最终版本):Theclosuretypeforalambda-expressionwithnolambda-capturehasapublicnon-virtualnon-explicitconstconversionfunctiontopointertofunctionhavingthesameparameterandreturntypesastheclosuretype’sfunctioncalloperator.我理解为什么无法从有状态lambda中获取函数指针,因为函数指针本身不能保存任何数据。但是当捕获的对象只是一个静态成员/静

c++ - "Undefined reference"到定义的构造函数

我有一个构造函数,其签名是这样的:cpuInput(conststd::string&label);实际的构造函数使用一个引用超构造函数的初始化列表,所以它看起来像这样:cpuInput::cpuInput(conststring&label):StateMonitor::input(label){}该类可以很好地编译为目标文件。如果我将该文件与调用构造函数的驱动程序一起编译:cpuInput*cpu=newcpuInput();当然,我从g++得到一个错误:demo.cpp:15:31:error:nomatchingfunctionforcallto‘cpuInput::cpuIn

如何正确地从函数(type_traits)提供向量

我如何返回std::vector由此operator+()?#include#include#include#include#includetemplatestructis_std_vector:std::false_type{};templatestructis_std_vector>:std::true_type{};templatestd::enable_if_t>::value>operator+(T&&vec1,T&&vec2){for(inti=0;i(vec2.at(i)));returnvec1;}intmain(){std::vectorvec1{1,2,3,4,5};std

c++ - 如何在 C++11 中将容器 std::array<type, size> 用于多维数组?

例如,包含三个整数的一维数组可以定义为std::arraymyarray或myarray[3].有没有像std::array这样的容器对于像myarray[3][3]这样的多维数组? 最佳答案 一个关键部分是确保{}初始化工作类似于std::array,并尽可能合理地让自己保持pod状。与std::array的兼容性也很重要,什么比std::array更兼容??所以我的解决方案从std::array中生成多维数组小号:templatestructmulti_array_helper{usingtype=T;};templateusi

c++ - 从 back_insert_iterator 中提取容器的 value_type 的特征类

std::back_insert_iterator的value_type等于void,但它还有一个protected成员container包含指向底层Container的指针。我正在尝试编写一个traits类来提取容器的value_type,如下所示:#include#include#includetemplatestructoutit_vt:OutputIt{usingself_type=outit_vt;usingvalue_type=typenamestd::remove_pointer_t().container)>::value_type;};intmain(){std::v