草庐IT

target_compile_definitions

全部标签

c++ - "All memory allocated on the stack is known at compile time"是什么意思?

阅读thisgreattutorial关于堆栈与堆,我对这句话有疑问:在堆栈上分配的所有内存在编译时都是已知的。我的意思是,如果我处于取决于用户输入的for循环中(i从0到X),并且在for我在堆栈上分配内存(例如创建一些类的新实例并放入类容器中),它不知道编译程序时堆栈将如何增长(它错过了用户的输入)。我是不是误会了什么? 最佳答案 对读者来说,所做的陈述稍微简化了一点。你是对的,堆栈本质上是动态的,实际分配的数量可能因动态输入而异。这是一个带有递归函数的简单示例:voidf(intn){intx=n*10;if(x==0)ret

c++ - 析构函数 : triviality vs implicit definition

根据我对标准的理解,普通析构函数是一种隐式声明的析构函数,其类只有基本和非静态成员以及普通析构函数。鉴于此定义的递归性,在我看来,唯一的“递归停止”条件是找到具有非隐式声明的析构函数(即用户声明的)的基类或非静态成员。如果那是对的,那应该意味着一个普通的析构函数是一个“不需要做任何事情”的析构函数,因此它将被声明(隐式地)但不被定义。换句话说:根据标准定义,隐式定义析构函数(即“它做某事”)不能是微不足道的说法是否正确?很抱歉提出这种愚蠢的问题,但我想澄清一下我的想法...... 最佳答案 没有。隐式定义的平凡析构函数根据定义是平凡

c++ - MSVC : what compiler switches affect the size of structs?

我有两个单独编译的DLL,一个是从VisualStudio2008编译的,一个是从matlab编译的mex文件。两个DLL都包含一个头文件。当我在一个DLL中采用sizeof()结构时,它返回48,而在另一个DLL中它返回64。我检查了/Zp开关,在两个编译中它都设置为/Zp8。还有哪些其他编译器开关可能会影响结构的大小?该结构是一个简单的POCO,没有继承,也没有虚函数。编辑结构看起来像这样:classLIBSPECSGeometry{public:std::vectorm_i;uintN;uintn_im,n_s;};在调试中,sizeof()在两种情况下都返回56,在发行版中,在

C++ 模板 : How to conditionally compile different code based on data type?

这里有一个小例子来说明我的问题的本质:#includeusingnamespacestd;typedefcharachar_t;templateclassSTRING{public:T*memory;intsize;intcapacity;public:STRING(){size=0;capacity=128;memory=(T*)malloc(capacity*sizeof(T));}constSTRING&operator=(T*buf){if(typeid(T)==typeid(char))strcpy(memory,buf);elsewcscpy(memory,buf);ret

C++ 单例用法 : compiler complains about private constructor

我知道有一百万个关于单例的问题和答案,但我似乎无法找到解决方案。所以冒着反对票的风险,这是我的问题:我想使用AndreiAlexandrescu的现代C++设计中的单例实现:标题:classSingleton{staticSingleton&Instance();private:Singleton(){};Singleton(constSingleton&){};Singleton&operator=(constSingleton&){};~Singleton(){};};实现:#include"s.hh"Singleton&Singleton::Instance(){staticSi

SSLHandshakeException: unable to find valid certification path to requested target 如何解决

事件描述对接单点登录过程中,有一个环节是根据拿到的code去认证中心获取用户token,在请求过程中报错SSLHandshakeException:unabletofindvalidcertificationpathtorequestedtarget搜索历程chatgpt回答:当Java作为客户端时,可能会遇到“SSLHandshakeException:unabletofindvalidcertificationpathtorequestedtarget”异常,这通常是因为客户端无法验证服务器的SSL证书。为了解决这个问题,可以尝试以下方法:检查服务器SSL证书是否有效且未过期。确保客户端拥

c++ - 错误 : C2988: unrecognizable template declaration/definition

我的两个模板的标题中出现错误。两者都有类似的声明和定义如下:templatevoidsetVideoCodecOption(T1AVCodecContext::*option,T2(CR2CVideoCodecSettings::*f)()const);templatevoidEncoderPrivate::setVideoCodecOption(T1AVCodecContext::*option,(CR2CVideoCodecSettings::*f)()const){T2value=(m_videoSettings.*f)();if(value!=-1){m_videoCodecC

c++ - Visual Studio 2017 : _mm_load_ps often compiled to movups

我正在查看为我的代码生成的程序集(使用VisualStudio2017)并注意到_mm_load_ps经常(总是?)编译为movups。我使用_mm_load_ps的数据定义如下:structalignas(16)Vector{floatv[4];}//oftenembeddedinotherstructslikethisstructAABB{Vectormin;Vectormax;boolintersection(/*parameters*/)const;}现在,当我使用这个构造时,会发生以下情况://thiscode__mm128bb_min=_mm_load_ps(min.v);

c++ - Gtest : test compiling error

我正在尝试测试我用googletest编写的电机控制库,但我没有编译测试代码。测试位于名为test.cpp的文件中,如下所示:#include#include"../motor.hpp"TEST(constructorTest,contructorDefault){}我将测试主函数放在另一个名为main.cpp的文件中。#include#include"../motor.hpp"intmain(intargc,char*argv[]){::testing::InitGoogleTest(&argc,argv);RUN_ALL_TESTS();}为了编译,我执行了以下行:g++main.

c++ - Boost Gzip 过滤器 : compile failes

我正在尝试从BoostGzip过滤器页面编译示例:#include#include#include#include#includeintmain(){usingnamespacestd;ifstreamfile("hello.gz",ios_base::in|ios_base::binary);filtering_streambufin;in.push(gzip_decompressor());in.push(file);boost::iostreams::copy(in,cout);}遗憾的是我的g++返回错误:gzlib.cpp:Infunction‘intmain()’:gzli