草庐IT

static_warning

全部标签

c++ - 带有 boost::shared_ptr 的 static_cast?

static_cast与boost::shared_ptr的等价物是什么?也就是说,我要如何重写下面的内容Base*b=newDerived();Derived*d=static_cast(b);当使用shared_ptr时?boost::shared_ptrb(newDerived());boost::shared_ptrd=??? 最佳答案 使用boost::static_pointer_cast:boost::shared_ptrb(newDerived());boost::shared_ptrd=boost::static_

c++ - 弃用 static 关键字...不再?

在C++中,可以在翻译单元中使用static关键字来影响符号(变量或函数声明)的可见性。在n3092中,这已被弃用:AnnexD.2[depr.static]Theuseofthestatickeywordisdeprecatedwhendeclaringobjectsinnamespacescope(see3.3.6).在n3225中,这已被删除。onlyarticleIcouldfind有点不正式。它确实强调了,为了与C的兼容性(以及将C程序编译为C++的能力),弃用是令人讨厌的。但是,将C程序直接编译为C++可能已经是一种令人沮丧的体验,因此我不确定是否值得考虑。有谁知道为什么改

c++ - static_assert 有什么作用,你会用它做什么?

你能举一个例子,static_assert(...)('C++11')可以优雅地解决手头的问题吗?我熟悉运行时assert(...)。我什么时候应该更喜欢static_assert(...)而不是常规的assert(...)?另外,在boost中有一个叫做BOOST_STATIC_ASSERT的东西,和static_assert(...)一样吗? 最佳答案 静态断言用于在编译时进行断言。当静态断言失败时,程序根本无法编译。这在不同的情况下很有用,例如,如果您通过代码实现某些功能,该代码严重依赖于恰好具有32位的unsignedint

objective-c - 将未知行数添加到 'Static Cells' UITableView

我在InterfaceBuilder中创建了一个静态表,其中包含6个部分,所有部分的行数都不同。我现在想添加具有不同行数的第7部分。首先,一旦我取消注释由Xcode插入的标准表委托(delegate)方法,我就会在self.tableView.tableHeaderView=containerView;我在表格中添加了标题。更重要的是,下面的代码让我崩溃了-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{return7;}-(NSInteger)tableView:(UITableView*)tableVie

objective-c - 定义缓存变量时在objective-c中使用static关键字

我正在查看以下苹果示例源代码:/*Cachetheformatter.Normallyyouwoulduseoneofthedateformatterstyles(suchasNSDateFormatterShortStyle),butherewewantaspecificformatthatexcludesseconds.*/staticNSDateFormatter*dateFormatter=nil;if(dateFormatter==nil){dateFormatter=[[NSDateFormatteralloc]init];[dateFormattersetDateForm

objective-c - 动态转发 : suppress Incomplete Implementation warning

我有一个公开一些方法的类,其实现由内部对象提供。我正在使用前向调用在运行时将方法调用分派(dispatch)给内部对象,但XCode提示,因为它找不到已声明方法的实现。我在SO上发现了一些其他类似的问题,但都通过设计更改解决了。我不想在这里讨论设计,但如果有人对此有任何建议,我有一个openquestion关于CodeReview,更适合这类讨论。我的问题是这里是否存在关闭XCode中IncompleteImplementation警告的方法。 最佳答案 您可以通过添加来抑制IncompleteImplementation警告#pr

ios - 'supportedInterfaceOrientations' : - Warning 实现中的返回类型冲突

升级到Xcode7.0后,我在UIViewControllerRotation方法中收到警告:-(NSUInteger)supportedInterfaceOrientations:Conflictingreturntypeinimplementationof'supportedInterfaceOrientations':'UIInterfaceOrientationMask'(aka'enumUIInterfaceOrientationMask')vs'NSUInteger'(aka'unsignedint')为什么会这样,我该如何解决?编辑:如果你去定义你会看到返回类型实际上已经

c++ - Clang 和 GCC vs MSVC 和 ICC : Is a static_assert in the copy/move constructor required to work, 如果复制/移动省略也可以应用?

我的模板结构的移动构造函数中有一个static_assert。编译器是否需要考虑这个static_assert,即使复制省略是可能的?这是精简的场景:#includetemplatestructX{X(X&&){static_assert(std::is_same::value,"IntentionalFailure");}};autoimpl()->X;autotest()->decltype(impl()){returnimpl();}intmain(){test();}GCC和Clang同意评估static_assert并且编译失败。另一方面,MSCV和ICC可以很好地编译代码。

c++ - Clang 和 GCC vs MSVC 和 ICC : Is a static_assert in the copy/move constructor required to work, 如果复制/移动省略也可以应用?

我的模板结构的移动构造函数中有一个static_assert。编译器是否需要考虑这个static_assert,即使复制省略是可能的?这是精简的场景:#includetemplatestructX{X(X&&){static_assert(std::is_same::value,"IntentionalFailure");}};autoimpl()->X;autotest()->decltype(impl()){returnimpl();}intmain(){test();}GCC和Clang同意评估static_assert并且编译失败。另一方面,MSCV和ICC可以很好地编译代码。

php - PHP 中的 self::$bar 和 static::$bar 有什么区别?

下面例子中使用self和static有什么区别?classFoo{protectedstatic$bar=1234;publicstaticfunctioninstance(){echoself::$bar;echo"\n";echostatic::$bar;}}Foo::instance();产生12341234 最佳答案 当您使用self来指代类成员时,您指的是在其中使用关键字的类。在这种情况下,您的Foo类定义了一个名为$bar的protected静态属性。当您在Foo类中使用self来引用该属性时,您引用的是同一个类。因此,