草庐IT

static_pointer_cast

全部标签

c# - "a field initializer cannot reference non static fields"在 C# 中是什么意思?

我不明白C#中的这个错误errorCS0236:Afieldinitializercannotreferencethenon-staticfield,method,orproperty'Prv.DB.getUserName(long)'对于下面的代码publicclassMyDictionary{publicdelegateVNonExistentKey(Kk);NonExistentKeynonExistentKey;publicMyDictionary(NonExistentKeynonExistentKey_){}}classDB{SQLiteConnectionconnecti

php - 使用 static::MY_CONST vs self::MY_CONST vs SomeClass::MY_CONST 引用 PHP 7 中的常量

我想一劳永逸地讲清楚。我很确定我知道何时使用self::MY_CONST和SomeClass::MY_CONST但不清楚何时使用static::MY_CONST.Youuseself::MY_CONST……当您引用常量在您调用它的同一个类中定义时。例子:classFoo{constMY_CONST=123;publicfunctionexample(){echoself::MY_CONST;}}YouuseAnotherClass::MY_CONST……当你引用一个常量在你调用它的不同类中定义。例子:classBar{constMY_CONST=123;}classFoo{public

java - 在java中, "public static void main"可以重命名或重构吗?

我不想更改签名的publicstaticvoid...String[]args部分,但是是否可以“重命名”此函数(例如,只是为了好玩)?因此执行的入口点将是一个具有另一个名称的函数。将它重命名为,例如boot(如果不是历史的话,什么能更好地反射(reflect)它在我的特定情况下的实际用途)。相关我有兴趣做一些不同的事情,但这些问题仍然很有趣:publicstaticvoidmain(Stringarg[])injavaisitfixed?Whythenamemainforfunctionmain() 最佳答案 没有。JavaLan

c++ - MISRA C++ 2008 规则 5-2-7 直接或间接违反 : An object with pointer type shall not be converted to an unrelated pointer type,

在下面的例子中:voidbad_function(){char_t*ptr=0;//MISRAdoesn'tcomplainshere,itallowscastofchar*tovoid*pointervoid*p2=ptr;//thefollowing2MISRAviolationsarereportedineachofthecastsbellow(twopercodeline)//(1)Eventmisra_violation:[Required]MISRAC++-2008Rule5-2-7violation:Anobjectwithpointertypeshallnotbecon

c++ - QT 插槽 : Pointer to Member Function error

我目前正在做一个Qt项目,我在SLOT方面遇到了一些麻烦。我想将一个指向成员函数的指针作为SLOT的参数传递。为此,我在类里面声明了SLOT,但是当我这样做时,出现了MOC错误。我不知道我想要实现的目标是否有可能实现。名为MainFrame的类的语法示例:voidslotAnswerReceived(QStringanswer,void(MainFrame::*ptr)(QString));我在任何地方都没有任何连接,没有任何东西使用该功能,我遇到的唯一错误是上面这一行。谢谢大家的帮助。我在网上找不到任何解决方案(但我发现这篇文章解释了SIGNALandSLOTindepth,如果有人

c++ - 如何很好地将 "cast"qint64 转换为 QProgressBar 的 int

我正在使用QFtp(是的..我知道)并且一切正常。使用他们自己示例中的代码作为指导。http://doc.qt.io/archives/qt-4.7/network-qftp-ftpwindow-cpp.html我遇到的唯一问题是在发送(或接收)大文件(比如3GB)时进度条出现故障。这是由于从qint64到int的转换:voidFtpWindow::updateDataTransferProgress(qint64readBytes,qint64totalBytes){progressDialog->setMaximum(totalBytes);progressDialog->setV

C++ 是否 reinterpret_cast 总是返回结果?

我有两个类,A和B。A是B的父类,我有一个函数接收指向A类型类的指针,检查它是否也是B类型,如果是将调用另一个函数,该函数接受一个指向类型B的类的指针。当函数调用另一个函数时,我提供reinterpret_cast(a)作为参数。如果这看起来模棱两可,这里有一个代码示例:voidabc(A*a){if(a->IsA("B")){//pleasedontworrymuchaboutthisline,//myrealconcernisthereinterpret_castdef(reinterpret_cast(a));};};现在您知道我是如何调用“def”的了,我想知道reinterp

c++ - 如何避免在 C++ 中将 const_cast 与 std::vector::erase() 一起使用?

我有这样一个类:templateclassAdjacencyList{public:voiddelete_node(constT&);protected:consttypenamestd::vector::const_iterator_iterator_for_node(conststd::vector&,constT&);};templatevoidAdjacencyList::delete_node(constT&node){_nodes.erase(_iterator_for_node(_nodes,node));}templateconsttypenamestd::vector

c++ - "static initialization"到底是什么意思?

我一直在阅读有关C++11中的POD的文章,我读过的几个地方都提到了支持静态初始化的POD。例如:OnStackOverflow:TheideaofaPODistocapturebasicallytwodistinctproperties:1.Itsupportsstaticinitialization,and2.CompilingaPODinC++givesyouthesamememorylayoutasastructcompiledinC.(只有粗体部分是相关的)OnWikipedia:Atypethatistrivialcanbestaticallyinitialized.显然我

c++ - 使用默认值而不是异常来 boost numeric_cast<>?

每当boost的numeric_cast转换失败,抛出异常。boost中是否有类似的模板让我指定一个默认值,或者在这种情况下捕获异常是我唯一能做的?我不太担心所有额外异常处理的性能,但我宁愿使用标准模板也不愿编写无用的包装函数。另外,根据以往的经验,我认为boost很有可能真的有我想的,只是一直没有找到。 最佳答案 numeric_cast函数只是调用boost::numeric::converter具有默认参数的模板类。其中一个参数是OverflowHandler,默认值为def_overflow_handler,但您可以指定si