草庐IT

send_static_file

全部标签

c++ - static 关键字会影响作用域吗?

在C89中,static关键字会影响作用域吗?我的软件负责人告诉我:"Avariablemarkedstaticatthetopofafiledoesn'ttechnicallyhaveglobalscopeanylonger.Staticisascopequalifieraswellasastoragekeyword.Scopeisaconceptthatcoversvisibilityofsymbols,thoughvisibilityisautomaticallycompiledtohavestoragedurationintrinsicallytiedinbyalmostall

c++ - 如果我从不调用这个方法,我可以把 static_assert 放在类方法中吗?

这个版本根本无法编译:structA{voidfoo(){static_assert(0,"Fail");}};这个版本编译没有错误(至少在我的编译器版本中):templatestructB{voidfoo(){static_assert(x,"Fail");}};Bb;只有当我调用b.foo();时,第二个版本才编译失败,所以我想知道如果我从不调用方法,标准是否允许使用第二个版本>富?所有编译器都会以相同的方式运行吗?这不是未定义的行为吗?我想在代码中包含static_assert以在某些模板参数满足某些条件时禁止使用模板类的某些方法。static_assert的用法是否正确?我想在

C++ static const 和初始化(有没有惨败)

我在久违后重返C++,我对众所周知的静态初始化问题的理解有些磕磕绊绊。假设我有一个简单的类Vector2,如下所示(请注意,我知道x和y应该与getter和setter私有(private),为简洁起见,这些只是被省略了):classVector2{public:Vector2(floatx,floaty):x(x),y(y){};floatx,y;}现在,如果我想指定一个静态常量成员来表示x和y设置为1的Vector2,我不确定如何进行——静态常量成员是否会陷入静态初始化问题或让他们const意味着他们还好吗?我正在考虑以下可能性:可能性一://.hclassVector2{publ

c++ - 定义一个类的私有(private)整型常量 : in the header or in the cpp file?

主题主要在此处解决(Wheretodeclare/defineclassscopeconstantsinC++?)特别是here.我想完全理解的是,在积分常数的情况下,它们之间有什么区别://IntheheaderclassA{private:staticconstintmember=0;//Declarationanddefinition};和://IntheheaderclassA{private:staticconstintmember;//Onlydeclaration};//InthecppconstintA::member=0;//Definition(据我所知,第二种可能

c++ - 带有返回 const 引用的隐式转换运算符的类的 static_cast<> 行为

我有以下类(class)(精简后只包含相关部分):#includeclassText{private:std::string_text;public:Text(std::string&&text):_text(std::move(text)){}operatorconststd::string&()const{return_text;}};我的问题是:如果我想获得一个conststd::string&,我可以这样做而不会受到任何惩罚吗:Texttext("fred");auto&s=static_cast(text);或者这会构造一个我最终得到引用的中间std::string吗?这种情

c++ - 如何比较 time_t 和 std::filesystem::file_time_type

我正在将一些代码从boost::filesystem转换到std::filesystem。以前使用的代码boost::filesystem::last_write_time()它返回一个time_t,因此直接与我已经持有的time_t对象进行比较是微不足道的。顺便说一句,我持有的这个time_t是从很久以前保存的文件内容中读取的,所以我坚持使用这种“自unix纪元以来的时间”类型。std::filesystem::last_write_time返回std::filesystem::file_time_type.是否有可移植的方法将file_time_type转换为time_t,或者以其

c++ - 解决 "only static const integral data members can be initialized within a class"编译错误

以下创建全局对象会导致编译错误。#include"stdafx.h"#includeusingnamespaceSystem;usingnamespacestd;#pragmahdrstopclassTester;voidinput();classTester{staticintnumber=5;public:Tester(){};~Tester(){};voidsetNumber(intnewNumber){number=newNumber;}intgetNumber(){returnnumber;}}TestertesterObject;voidmain(void){cout>ne

c++ - 使用自定义 std::ostream 包装 FILE*

我有一个与std::ostream一起工作的函数。我需要支持使用C文件句柄(FILE*)。我应该创建我自己的std::ostream的子类来委托(delegate)给FILE*吗? 最佳答案 正如BenVoigt所指出的,您想要子类化streambuf。南加州大学网站上的某些页面有documentation,header,和source对于包装FILE*的streambuf子类(stdiobuf)的GNU实现。它对作为(GroovX)一部分的库有一些依赖性,但这些应该很容易删除(我将从删除对GVX_TRACE的所有引用开始)。有趣的

如何使file_get_contents返回唯一结果

我是PHP的新手,想向您寻求帮助,以返回File_get_contents()的唯一结果。原因是我想给每张照片一个唯一的名称,因此以后可以删除其中一个,而不是全部。$file=addslashes(file_get_contents($_FILES['image']['tmp_name'][$key]));不幸的是,Time()和Microtime()在这种情况下无济于事。看答案也许这会帮助您:http://php.net/manual/en/function.uniqid.phpuniqid();$ImageName=$ImageName。'_'。uniqid();

c++ - static_cast 可以将非空指针转换为空指针吗?

我需要为回调函数编写代码(它将在ATL中调用,但这并不重要):HRESULTcallback(void*myObjectVoid){if(myObjectVoid==0){returnE_POINTER;}CMyClass*myObject=static_cast(myObjectVoid);returnmyObject->CallMethod();}这里的void*保证是指向CMyClass的指针,所以static_cast是合法的。我关心的是代码必须尽可能可移植(至少对于较新版本的VisualC++)。所以super偏执狂我也倾向于检查CMyClass*指针-我的意思是如果结果为空