草庐IT

tchar_pointer

全部标签

c++ - TCHAR* envp[] : What is it?

我用VisualStudio创建了一个VC++控制台项目,它自动生成了这个函数:int_tmain(intargc,TCHAR*argv[],TCHAR*envp[]){...}我只是想知道envp代表什么以及如何/何时可以/应该使用它?谢谢! 最佳答案 上面的envp参数将存储环境变量。Theenvparray,whichisacommonextensioninmanyUNIX®systems,isusedinMicrosoftC++.Itisanarrayofstringsrepresentingthevariablesseti

c++ - 是否有 boost::weak_intrusive_pointer?

出于遗留原因,我需要使用侵入式指针,因为我需要能够将原始指针转换为智能指针。但是我注意到没有用于boost的弱侵入性指针。我确实在boost线程列表中找到了有关它的讨论,但没有具体内容。有人知道弱侵入指针的线程安全实现吗?谢谢丰富 最佳答案 这没有任何意义。详细说明:weak_ptr指向与shared_ptr相同的counter对象实例。当shared_ptr超出范围时,counter的实例保持不变(有效计数为0),这允许weak_ptr实例检查它们是否有效地指向一个已释放的对象。使用侵入式计数,计数器集成在对象中。当计数达到0时,

c++ - 为什么将数组的地址分配给指针 "my_pointer = &my_array"是编译错误?

intmy_array[5]={0};int*my_pointer=0;my_pointer=&my_array;//compilererrormy_pointer=my_array;//ok如果my_array是数组的地址,那么&my_array会给我什么?我收到以下编译器错误:error:cannotconvert'int(*)[5]'to'int*'inassignment 最佳答案 my_array是一个由5个整数组成的数组的名称。编译器会很乐意将其转换为指向单个整数的指针。&my_array是一个指向5个整数数组的指针。编

C++11:将 std::is_pointer 扩展为 std::shared_ptr

我想重载std::is_pointer在C++11中为std::shared_ptr生成真值同样,因为后者的行为非常类似于T*.#includenamespacestd{templatestructis_pointer>:std::true_type{};templatestructis_pointer>:std::true_type{};}我想知道为什么这个重载还没有包含在标准实现中。有没有我忽略的陷阱?当然也可以引入一个新特性is_shared_ptr.其实我一开始就尝试了下面的代码:templatestructis_pointer::type>>:std::true_type{}

c++ - static_cast<Derived *>(Base pointer) 是否应该给出编译时错误?

static_cast(Basepointer)是否应该给出编译时错误?classA{public:A(){}};classB:publicA{public:B(){}};intmain(){A*a=newA();B*b=static_cast(a);//CompileError?} 最佳答案 它不会给出编译时错误,因为Base-Derived关系可以在运行时存在,具体取决于被强制转换的指针的地址。static_cast总是成功,但如果你不转换为正确的类型,则会引发undefined-behavior。dynamic_cast可能会

c++ - 更漂亮的 "pointer to last element"语法,std::vector?

我想知道是否有更漂亮的语法来获取指向C++vector中最后一个元素的普通指针(不是迭代器)std::vectorvec;int*ptrToLastOne=&(*(vec.end()-1));//theotherwayIcouldseewasint*ptrToLastOne2=&vec[vec.size()-1];但是这两个都不是很好看! 最佳答案 int*ptrToLastOne=&vec.back();//precondition:!vec.empty() 关于c++-更漂亮的"po

c++ - "smart pointer to member"的真实示例是什么?

为了澄清英语中可能存在的优先级歧义:我们正在讨论“智能(指向成员的指针)”,而不是“指向成员的(智能指针)”。我会将指向成员的智能指针定义为带有operator->*(T*lhs,Xrhs)的类X。在他的文章"Implementingoperator->*forSmartPointers",ScottMeyers只是简单地触及smart指向成员的指针,因为当时(1999年)具体问题对于原始指向成员的指针(旁注:后者可以用lambdahere优雅地解决)。无论如何,ScottMeyers在脚注中写道:Shortlyafterwritingthedraftofthisarticle,one

c++ - 如何计算 std::basic_string<TCHAR>

我正在尝试找出basic_string.但是cout正在抛出错误。我能知道怎么做吗 最佳答案 正如dauphic所说,std::wcout用于宽字符串,std::cout用于窄字符串。如果您希望能够为任何一种类型的字符串进行编译(TCHAR旨在使这种事情变得更容易),这样的事情有时会让生活变得更轻松:#ifdefined(UNICODE)||defined(_UNICODE)#definetcoutstd::wcout#else#definetcoutstd::cout#endif使用tcout代替。

c++ - C/C++ : Optimization of pointers to string constants

看看这段代码:#includeusingnamespacestd;intmain(){constchar*str0="Watchmen";constchar*str1="Watchmen";char*str2="Watchmen";char*str3="Watchmen";cerr(const_cast(str0))(const_cast(str1))(str2)(str3)产生这样的输出:0x4430000x4430000x4430000x443000这是在Cygwin下运行的g++编译器上。即使没有开启优化,指针也都指向同一个位置(-O0)。编译器是否总是优化得如此之多,以至于它会

c++ - 表达式 : auto p {make_pointer()}; 的不同编译器行为

以下程序的正确行为是什么?//example.cpp#include#includestructFoo{voidBar()const{std::coutMakeFoo(){returnstd::make_shared();}intmain(){autop{MakeFoo()};p->Bar();}当我在我的LinuxRHEL6.6工作站中编译它时,我得到以下结果:$g++-vgccversion5.1.0(GCC)$g++example.cpp-std=c++14-Wall-Wextra-pedantic$./a.outFoo::Bar()但是$clang++-vclangversio