草庐IT

cast-expression

全部标签

c++ - MFC 是否仅适用于 Visual Studio 而不是 Visual C++ Express?

MFC只能与VisualStudio一起使用,还是也可以与VisualC++Express一起使用? 最佳答案 现在有一个解决这个问题的方法,对于所有想使用免费版本的人。VisualStudioCommunity2013附带MFC(Microsoft基础类)。下载链接:https://www.visualstudio.com/products/visual-studio-community-vs编辑:VisualStudioCommunity2015现已发布。 关于c++-MFC是否仅适

c++ - C++ : "expected primary-expression before ‘>’ token"中的两个模板

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭7年前。最小工作示例:#includestructPrinter{templatestaticvoidprint(Telem){std::coutstructMain{templatevoidprint(Telem){//Inthiscase,thecompilercouldguessTfromthecontext//Butinmycase,assumethatIneedtospecifyT.printer_t::print(e

c++ - 警告 : Comparison between signed and unsigned integer expression

我在codepad.org上运行以下代码时出现此错误。“在成员函数‘doubleXchange::getprice(std::string)’中:第87行:警告:有符号和无符号整数表达式之间的比较”这是我的代码:#include#include#includeusingnamespacestd;classXchange{public:Xchange();//doesnothing(?)doublegetprice(stringsymbol);private:vectorstocks;};doubleXchange::getprice(stringsymbol){for(inti=0;i

c++ - reinterpret_cast 本身会导致异常吗?

假设我有一个名为A的类和一个空指针vp。以下是否会导致异常?A*ap=reinterpret_cast(vp);谢谢,飞悦 最佳答案 不,都不是reinterpret_cast其C风格的转换等价物也不会执行任何检查,因此它们本身不会导致异常。显然,由于这两种构造都尽可能不安全,因此取消引用结果指针ap可能导致未定义的行为。 关于c++-reinterpret_cast本身会导致异常吗?,我们在StackOverflow上找到一个类似的问题: https://s

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

c++ - static_cast wchar_t* 到 int* 或 short* - 为什么它是非法的?

在MicrosoftVC2005和g++编译器中,以下会导致错误:在win32VC2005上:sizeof(wchar_t)为2wchar_t*foo=0;static_cast(foo);结果errorC2440:'static_cast':cannotconvertfrom'wchar_t*'to'unsignedshort*'...在MacOSX或Linuxg++上:sizeof(wchar_t)为4wchar_t*foo=0;static_cast(foo);结果error:invalidstatic_castfromtype'wchar_t*'totype'unsignedi

c++ - "cast"指向 C++ 中函数指针的成员函数指针的最简单方法是什么?

我想为STL算法的“comp”参数提供一个成员函数,例如lower_bound(...,Comparecomp)。comp()函数访问非静态成员字段,因此它本身必须是非静态成员,但非静态成员函数指针的类型与普通函数指针的类型不同。解决这个问题的最佳方法是什么? 最佳答案 这是std::mem_fun和std::mem_fun_ref最常见的用法。它们是创建调用指定成员函数的仿函数的模板。TR1添加了一个std::tr1::bind,它也很有用且用途更广(如果您没有可用的TR1,那是基于Boost::bind的)。C++0x将在标准库

C++ strict-aliasing agnostic cast

我在StackOverflow中阅读了很多关于严格别名的QA,但它们都很常见,而且讨论总是倾向于引用C++标准的深层细节,这些细节几乎总是难以正确理解。特别是当标准不直接说,而是用一种含糊不清的方式描述某些东西时。所以,我的问题可能与这里的大量QA重复,但是请只回答一个具体问题:做一个“nonalias_cast”是正确的方法吗?:templateinlineautononalias_cast(IN*data){char*tmp=reinterpret_cast(data);returnreinterpret_cast(tmp);}floatf=3.14;unsigned*u=nona

c++ - "dynamic_cast"之后的 NULL 指针实际上可以取消引用吗?

以下代码编译正确并得到神秘的输出:specialInvestmentfunction00000000(环境:C++VS2010)#include#includeusingnamespacestd;classSecurity{public:virtual~Security(){}};classStock:publicSecurity{};classInvestment:publicSecurity{public:voidspecial(){cout(p)->special();cout(p)怎么可能呢?取消引用NULL指针并获得“正确”输出而不是崩溃?是VS2010的特殊“特性”吗?现在

java - 'Conditional expressions can be only boolean, not integral.' 是什么意思?

“条件表达式只能是boolean值,不能是整数。”是什么意思?意思?我不知道Java,我知道C++deffenetly不足以理解它的含义。请帮助(在比较C++和Java项目7子项目1中的http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html中找到) 最佳答案 这意味着您需要一个boolean值作为条件,从整数类型的转换不会是隐式的。而不是if(x)你需要if(x!=0)等前者是一个int,在C++中将隐式转换为bool(通过!=0