草庐IT

init-method

全部标签

c++ - 干净地抑制 gcc 的 `final` 建议警告 (`-Wsuggest-final-types` 和 `-Wsuggest-final-methods` )

我喜欢使用-Wsuggest-final-types编译我的代码和-Wsuggest-final-methods以便在可能使用final关键字以允许编译器更积极地优化的机会时收到警告。不过,有时这些建议是不正确的-例如,我有一个类Base和一个virtual~Base()析构函数,在另一个项目中以多态方式使用,gcc建议我可以将Base标记为final。有没有办法“干净地”告诉编译器Base是多态使用的,不应该被标记为final?我能想到的唯一方法是使用#pragma指令,但我发现它会使代码困惑且难以阅读。理想情况下,我正在寻找可以添加到类/方法声明前/后的非最终关键字或属性。

c++ - Clang 的写法中的 "annotated fallthrough"和 "partly annotated method"是什么?

我正在将Clang错误消息翻译成另一种语言,在文件底部附近我发现了以下条目:defwarn_unannotated_fallthrough:Warning,InGroup,DefaultIgnore;和defwarn_unannotated_fallthrough_per_function:Warning,InGroup,DefaultIgnore;我试图搜索这些警告的提及,并找到了这个代码片段:intfallthrough(intn){switch(n/10){case0:n+=100;-case1://expected-warning{{unannotatedfall-throug

c++ - 为什么 braced-init-list 在函数调用和构造函数调用中的行为不同?

使用clang3.5.0和gcc4.9.1编译以下代码会在最后一条语句处产生错误。#includestructFoo{Foo(intx,inty){std::cout为什么Foo({1,2})可以,而bar({1,2})不行?特别是,如果能了解基本原理会很棒。 最佳答案 Foo({1,2})创建一个临时Foo对象并调用复制构造函数。请参阅此修改后的带有复制构造函数删除的示例:http://coliru.stacked-crooked.com/a/6cb80746a8479799它的错误是:main.cpp:6:5:note:cand

iphone - 在 init 中声明 block 安全吗?

我需要调用一个带有block的函数。如果我在init方法内部这样做会导致问题吗?-(id)initWithObjectThatWantsABlock:(Blar*)blar{if((self=[superinit])){[blartakeBlock:^{NSLog(@"Hi");}];}} 最佳答案 是的。它仍然只是一个函数,只要它不依赖于您尚未初始化的任何东西,它应该没问题。 关于iphone-在init中声明block安全吗?,我们在StackOverflow上找到一个类似的问题:

iphone - UILocalizedIndexedCollat​​ion 的 sectionForObject :(id)object collationStringSelector:(SEL)selector method 选择器的作用是什么

我是iOS开发的初学者,正在经历this文档(关于使用索引列表配置TableView的iOS开发人员指南)我遇到了这个://Listing4.7for(State*theStateinstatesTemp){NSIntegersect=[theCollationsectionForObject:theStatecollationStringSelector:@selector(name)];theState.sectionNumber=sect;}我无法弄清楚选择器(@selector(name))及其用途,也无法找到在选择器中传递名称的方法,即name.我在谷歌上搜索示例以找到更好的

ios - 在 alloc 和 init 上保留计数

有些网站是这样说的:@property(nonatomic,strong)MyObject*foo;self.foo=[[MyObjectalloc]init];将保留计数增加到2但是自从最新的xcode版本或ARC,这应该不是问题吧?根据视频我们可以去掉所有的autorelease因此:@property(nonatomic,strong)MyObject*foo;self.foo=[[[MyObjectalloc]init]autorelease];变成这样@property(nonatomic,strong)MyObject*foo;self.foo=[[MyObjectallo

iphone - 调用[[super allocWithZone :nil] init], 消息机制

e.(只是为了更清楚地理解消息机制)我有课我的类.h@interfaceMyClass:NSObject{intivar1;intivar2;}+(id)instance;@endMyClass.mstaticMyClass*volatile_sInstance=nil;@implementationMyClass+(id)instance{if(!_sInstance){@synchronized(self){if(!_sInstance){_sInstance=[[superallocWithZone:nil]init];}}}return_sInstance;}@end调用[su

ios - animationDidStop : finished: delegate method not getting called

我想在前一个动画例程完成后立即开始一个新的动画例程。然而,当前一个确实完成时,新的不会被触发,因为没有调用委托(delegate)方法。我已经委派了一个ViewController来处理按钮的CALayer的动画。“buttonSlide”是以前的动画,而“buttonFade”是新动画。这是代码片段:--(void)viewWillAppear:(BOOL)animated{NSLog(@"TimeViewappearing...");[superviewWillAppear:animated];[selfpressButton:nil];//Showscurrenttimeasso

ios - 如果你不能先调用 [super init] 怎么办

我正在尝试对UIPopoverController进行子类化,并赋予IT确定要创建和呈现哪种UIViewController(contentViewController)的适当责任,而不是将弹出窗口的调用代码与该责任搞得一团糟。但我遇到了几个问题。根据Apple文档,在第一次调用之前没有正当理由做任何事情。if(self=[superinit])所以我尝试了这一点,认为当我的代码检查我传入的数据并决定创建和发送哪个UIViewController时,我可以稍后在方法中简单地设置contentViewController属性,但是调用[superinit]时出现错误,告诉我必须调用另一个

ios - 使用 ARC 启用项目的仪器中的 [[NSNumberFormatter alloc] init] 中出现内存泄漏

在我的项目中NSNumberFormatter发生有线内存泄漏。当我在Instrument中检查我的应用程序时,我遇到了很多框架泄漏,其中一个非常令人惊讶的泄漏是NSNumberFormatter在我分配该格式化程序对象时泄漏。这是我格式化数字值的函数://SetNumberFormatter-Like1000=1,000+(NSString*)getNumberWithNumberFormate:(NSString*)dataVal{NSNumberFormatter*aNumberFormatter=[[NSNumberFormatteralloc]init];[aNumberFo