草庐IT

GET_MEMFUN_CLASS

全部标签

C++ 风格约定 : Parameter Names within Class Declaration

我是一个相当新的C++程序员,我想听听支持和反对在类声明中命名参数的争论。这是一个例子:Student.h#ifndefSTUDENT_H_#defineSTUDENT_H_#includeusingnamespacestd;classStudent{private:stringname;unsignedintage;floatheight,GPA;public:Student(string,unsignedint,float,float);voidsetAge(unsignedint);};#endif/*STUDENT_H_*/对比#ifndefSTUDENT_H_#defineS

c++ - c++ 中是否有任何类是所有类的父类(super class)?

像javaJava.lang.Object是所有类的父类(superclass)所以在C++中是否有任何类像对象? 最佳答案 不,没有。在C++中,您为使用的东西付费,而不是更多。你可以有void*可以指向任何东西,或者如果有意义的话,写你自己的基类。 关于c++-c++中是否有任何类是所有类的父类(superclass)?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/1831

c++ - std::future.get() 有时卡在 os x 中

我有两个线程,一个线程应该接收和处理来自另一个线程的请求。第二种是同步传输请求和接收响应。我尝试了以下方案:成对队列(值(value),promise)。第一个线程创建一个promise并将其插入同步队列并等待future.get()的返回值问题是有时线程卡在future.get()上,但是当我暂停程序执行并继续时它再次正常工作。这个stucks具有随机​​性。FutureQueue.h#ifndefFutureQueue_h#defineFutureQueue_h#include#include#include#include#includetemplateclassWork{pub

c++ - 模板类中函数指针的成员给出错误 : must be a class or namespace when followed by '::'

我试图在C++中声明一个模板函数指针。templateclassMyClass{public:typedefconstunsignedchar*(T::*MyTemplatedEvent)(unsignedlong&myParameter);};但出于某种原因,我不断收到此错误:'T':mustbeaclassornamespacewhenfollowedby'::'有人能告诉我哪里做错了吗?编译器应该知道T是一个类。它在MyClass声明上方这样说...... 最佳答案 对于T::*MyTemplatedEvent,您期望T是类类

c++ - 非类型模板参数 : how to pass reference to base class object?

似乎无法传递对的引用派生对象的基类对象作为模板参数,正如我在这里尝试做的那样:structa{int_v;constexpra():_v(0){}constexpra(intv):_v(v){}};structc:publica{constexprc():a(){}constexprc(intv):a(v){}};externconstcdefault_a;constexprconstcdefault_a{1};consta&c_as_a=default_a;//^--thisline(16)causesnoerror-ccanbeconvertedtoatemplatestructb

c++ - 对 C++ 中的 std::get_money 和 std::put_money 的混淆

我对C++函数感到困惑std::get_money在中定义头文件。get_money有什么用根据编程概念?我有以下代码使用std::get_money.#include//std::cin,std::cout#include//std::get_moneyintmain(){longdoubleprice;std::cout>std::get_money(price);if(std::cin.fail())std::cout当我输入100.25时,它返回100。输出和货币格式之间有什么关系?我读了this引用但无法理解关系。std::put_money也存在同样的混淆。,std::ge

C++ 模板 "class type"错误

我一直在研究一个链表模板类来对各种变量做同样的事情,并设法解决了大部分问题。除了编译时,我得到这些:g++-Wall-otemplate_testtemplate_test.cppInfileincludedfromtemplate_test.cpp:1:0:LinkedList.h:50:11:error:declarationof‘classType’LinkedList.h:7:11:error:shadowstemplateparm‘classType’LinkedList.h:51:30:error:invaliduseofincompletetype‘classLinked

c++ - 使用派生自 `std::get` 的元素在 `std::tuple` 上调用 `std::tuple` - 格式错误?

structY{};structX:std::tuple{};intmain(){std::get(std::make_tuple(X{}));}onwandbox当使用libc++时,上面的代码可以通过clang++编译并按预期工作。当使用libstdc++时,上述代码无法同时使用clang++和g++进行编译,并出现以下错误:include/c++/7.0.1/tuple:1302:36:error:nomatchingfunctionforcallto‘__get_helper(std::tuple&)’{returnstd::__get_helper(__t);}~~~~~~~

c++ - 为什么 injected-class-name 有时不被视为类模板中的模板名称?

SourceInthefollowingcases,theinjected-class-nameistreatedasatemplate-nameoftheclasstemplateitself:itisfollowedbyitisusedasatemplateargumentthatcorrespondstoatemplatetemplateparameteritisthefinalidentifierintheelaboratedclassspecifierofafriendclasstemplatedeclaration.所以我尝试检查所有3种情况(另外在基本歧义的情况下,尽管我

c++ - 为什么这个 get_index 实现在 VS2017 上失败了?

巴里给了我们thisgorgeousget_indexforvariants:templatestructtag{};templatestructget_index;templatestructget_index>:std::integral_constant...>(tag()).index()>{};按如下方式使用:usingV=variant;constexprconstsize_tN=get_index::value;//1它在Clang(OSX)中运行良好。但在VisualStudio2017中I'mgetting以下内容:(10):errorC2039:'index':is