草庐IT

non-void

全部标签

c++ - constexpr 类的设计 : merging constexpr and non-constexpr versions?

考虑一个在运行时只包装一个值的类:templateclassNonConstValue{public:NonConstValue(constType&val):_value(val){;}Typeget()const{return_value;}voidset(constType&val)const{_value=val;}protected:Type_value;};以及它的constexpr版本:templateclassConstValue{public:constexprConstValue(constType&val):_value(val){;}constexprTypeg

c++ - 处理比较 : empty classes vs. 未定义类与 void*

微软的GDI+定义了许多空类,在内部被视为句柄。例如,(sourceGdiPlusGpStubs.h)//Approach1classGpGraphics{};classGpBrush{};classGpTexture:publicGpBrush{};classGpSolidFill:publicGpBrush{};classGpLineGradient:publicGpBrush{};classGpPathGradient:publicGpBrush{};classGpHatch:publicGpBrush{};classGpPen{};classGpCustomLineCap{};

c++ - xvalues : differences between non class types and class types

考虑下面的最小示例:#includestructS{};intmain(){Ss;std::move(s)=S{};}它编译没有错误。如果我改为使用非类类型,则会收到错误。例如,以下代码无法编译:#includeintmain(){inti;std::move(i)=42;}枚举、作用域枚举等也是如此。错误(来自GCC)是:usingxvalue(rvaluereference)aslvalue这背后的原理是什么?我想这是对的,但我想了解我可以对除非类之外的所有类型执行此操作的原因是什么。 最佳答案 C++允许对类对象右值进行赋值,

c++ - 将 void (*p)(SomeType*) 转换为 void (*p)(void*) 是否安全

假设我有如下函数:voidfun(void*p){SomeType*p=reinterpret_cast(p);...}API需要签名。我只是想知道我能不能把它写成。voidfun(SomeType*p){...}并将其转换为void(*)(void*)。 最佳答案 虽然您可以将函数指针转换为其他函数指针并返回,但通过与其签名不匹配的指针调用函数是未定义的行为。您不能只是转换它并传递给API。在C和C++03中,您必须创建一个与签名匹配并执行转换的命名包装函数。在C++11及更高版本中,您可以只使用无捕获的lambda(正确转换):

c++ - G++ 编译器错误或错误代码? : "template definition of non-template"

作为大型程序的特征类的一部分,我尝试创建一个静态类变量,该变量可能具有不同的值,具体取决于实例化封闭类模板的类型。我已经简化了相关代码以生成我正在谈论的内容的简单示例:#include#include#includetemplatestructFoo;templatestructFoo::value>::type>{staticstd::stringmessage;};templatestructFoo::value>::type>{staticstd::stringmessage;};templatestd::stringFoo::message;对于GCC4.6,这会产生一个编译器

c++ - 调用 placement new 时,将指针强制转换为 "void*"有什么影响吗?

我正在审查自定义容器的代码,它的某些部分创建了如下元素:::new((void*)&buffer[index])CStoredType(other);有些人是这样的:::new(&buffer[index])CStoredType(other);所以两者都使用placementnew来调用复制构造函数来通过复制其他元素来创建元素,但在一种情况下,指向新元素存储的指针按原样传递,而在另一种情况下,它被转换为void*。转换为void*有什么影响吗? 最佳答案 是的,您可以为非空指针重载operatornew。强制转换确保采用void指

c++ - 静态 C++ 映射初始化错误 C2552 : non-aggregates cannot be initialized with initializer list

我正在尝试使用以下代码在header中初始化map,但它一直在标题中显示错误。我正在使用C++11,所以这应该是可能的,对吧?typedefstd::map>AnimationSpeedMap;AnimationSpeedMapAnimationSpeeds={{NPCAnimation::WALK,{{Direction::LEFT,sf::milliseconds(100)},{Direction::RIGHT,sf::milliseconds(100)},{Direction::UP,sf::milliseconds(200)},{Direction::DOWN,sf::mill

c++ - 从 void* 到基类指针的转换

我有一些层次结构:基类、派生类和一些将用户数据存储为void*的结构。该void可以存储Base和Derived类指针。主要问题是我不知道那里存储的是基指针还是派生指针。classBase{public:inttype;};classDerived:publicBase{};Base*base;//initbasepointerDerived*derived;//initderivedpointervoid*base_v=base;void*derived_v=derived;//voidpointersarecorrect.Theypointtobaseandderivedvaria

c++ - 是否可以检查函数是否具有 void 返回类型

出现了这个非常奇怪的请求......我需要在编译时检查当前函数是否有void返回类型,如果返回类型为void则编译失败。我试着用http://en.cppreference.com/w/cpp/types/result_of施展魔法和decltype也一样,但是我无法接近解决方案。#includevoidother_func(void){}voidtest_maxi(void){typedefdecltype(&::other_func)TYPE;static_assert(std::is_same::value,"notvoid");}intmain(){}那么问题来了:当前函数是否

新创建多模块工程执行maven编译打包出现non-resolvable parent pom异常

新创建多模块工程在执行mvncleaninstall时抛出non-resolvableparentpom找不到父pom异常:[FATAL]Non-resolvableparentPOMforcom.alibaba:*****:[unknown-version]:Couldnotfindartifactcom.-parent:pom:-SNAPSHOTand‘parent.relativePath’pointsatnolocalPOM@line12,column10解决办法在子模块标签内添加:../pom.xml原因pomparent标签寻找路径:relativePath本地仓库远程仓库因为是新