考虑以下类,实现移动构造函数的正确方法是什么:
class C {
public:
C();
C(C&& c);
private:
std::string string;
}
Run Code Online (Sandbox Code Playgroud)
当然,这个想法是避免复制string或解除分配两次.
让我们假设基本的例子只是为了清晰,我确实需要一个移动构造函数.
我试过了:
C::C(C&& c) {
//move ctor
string = std::move(c.string);
}
Run Code Online (Sandbox Code Playgroud)
和
C::C(C&& c) : string(std::move(c.string)) {
//move ctor
}
Run Code Online (Sandbox Code Playgroud)
两者都在gcc 4.8上编译正常并运行良好.这似乎选项A是正确的行为,string被复制,而不是使用选项B.移动
这是正确执行的举动构造的?
我有一个自定义子类,UILabel使用CoreText进行自定义绘图.我曾经使用在UIFont使用font属性访问它的标签上设置的字符串来绘制我的字符串.我还在字体中添加了一些特征.这是它的样子:
UIFont* font = [self font];
CTFontRef ref = CTFontCreateWithName((CFStringRef)[font name], [font pointSize], NULL);
CTFontRef italicFont = CTFontCreateCopyWithSymbolicTraits(ref, [font pointSize], NULL, kCTFontItalicTrait, kCTFontItalicTrait);
Run Code Online (Sandbox Code Playgroud)
这曾经很好地工作,直到新的ipad出现其视网膜显示器.当我执行CTFontCreateCopyWithSymbolicTraits调用时,它会产生一个nil返回值.我发现[font name]在这些新设备上返回".HelveticaNeueUI".在CTFontCreateWithName似乎好工作与这家民营字体的名字,但CTFontCreateCopyWithSymbolicTraits没有.然而,如果我使用[UIFont italicSystemFontOfSize:[font pointSize]]它创建一个斜体字体,则会创建一个[font name]仍然返回".HelveticaNeueUI" 的斜体字体.
我应该如何将我转换UIFont为CTFontRef能够CTFontRef在视网膜和非视网膜显示器上应用新的特征?
我如何用阴影掩盖CALayer,以便阴影只在路径之外?我不希望透明视图背后的阴影.
shadowLayer.shadowOffset = CGSizeMake(x, y);
shadowLayer.shadowRadius = radius;
shadowLayer.shadowOpacity = opacity;
shadowLayer.shadowColor = color.CGColor;
shadowLayer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个被覆盖的NSTextAttachment子类
attachmentBoundsForTextContainer:proposedLineFragment:glyphPosition:characterIndex:
imageForBounds:textContainer:characterIndex:.
我需要在某些时候重新绘制附件.调用setNeedsDisplayUITextView不起作用.
有任何想法吗?我想避免重新创建附件和/或属性字符串.
自从切换到XCode 4后,泄漏工具显示出大量泄漏,全部来自JSONKit和ASIHTTPRequest,运行2分钟后,我泄漏了数百个数组/字典/字符串(来自jk_create_dictionary,jk_parse_array,HTTPMessage ::*等)总计几百英尺KB.大多数堆栈跟踪不是源于我的任何调用,其余的完全是无辜的.我非常肯定不是XCode 4之前的情况.我不知道谁是罪魁祸首.任何见解都很可爱.
更新:
JSONKit泄漏可能是JSONDecoder缓存.
例如:
static JSONDecoder *decoder = nil;
if (!decoder)
decoder=[[JSONDecoder alloc] init];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[request setCachePolicy:ASIDoNotWriteToCacheCachePolicy];
[request setCompletionBlock:^{
NSData *response = [request responseData];
NSDictionary *json = [decoder objectWithUTF8String:[response bytes] length:[response length]];
// ...
}];
[request setFailedBlock:^{
// ...
}];
[request startAsynchronous];
Run Code Online (Sandbox Code Playgroud) 我是使用转换的新手.并且仍然担心他们的工作方式.
我正在尝试做的是以给定的角度旋转我的UIImageView.但旋转后,它会改变图像的大小,变小.我也正在为ImageView进行缩放,因此它不会颠倒.当分配ImageView时,如何旋转并保持CGRectMake中给出的大小?
UIImageView *myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x,y,width,height)];
myImageView.contentMode = UIViewContentModeScaleAspectFit;
[myImageView setImage:[UIImage imageNamed:@"image.png"]];
myImageView.layer.anchorPoint = CGPointMake(0.5,0.5);
CGAffineTransform newTransform;
myImageView.transform = CGAffineTransformMakeScale(1,-1);
newTransform = CGAffineTransformRotate(newTransform, 30*M_PI/180);
[self.window addSubview:myImageView];
Run Code Online (Sandbox Code Playgroud)
非常感谢!
我有兴趣将可变长度数组(附加 SSBO)传递给函数,即:
layout(std430) buffer ssbo {
type buffer[];
};
void func(buffer) {
buffer[...]
}
func(buffer);
Run Code Online (Sandbox Code Playgroud)
编辑:扩展规范明确指出这是不受支持的(问题#2 - https://www.opengl.org/registry/specs/ARB/shader_storage_buffer_object.txt)。因此,欢迎采取变通办法。
double volume(double l,double w,double h);
double area(double l,double w,double h);
int main() {
double l,w,h,v,a`;
volume (3.0,1.5,2.0);
area(3.0,1.5,2.0);
printf("The Volume is %lf cubic meters and the area is %lf square meters.\n", v,a);
return 0;
}
double volume(double l,double w,double h) {
double v;
v = l*w*h;
return v;
}
double area(double l,double w,double h) {
double a;
a = (2*l*w) + (2*w*h) + (2*l*h);
return a;
}
Run Code Online (Sandbox Code Playgroud)
体积是2091994552961492532068352.000000立方米,面积是637485042878638687518720.000000平方米.
我目前正在获得上述输出(这显然是错误的,垃圾值),我想知道我哪里出错了.我猜它是一个指针问题.如果你能解释一下我的指针基础知识,我将非常感激.提前致谢.
ios ×4
objective-c ×2
c ×1
c++ ×1
c++11 ×1
calayer ×1
cocoa-touch ×1
core-text ×1
function ×1
glsl ×1
instruments ×1
ios5 ×1
opengl ×1
pointers ×1
uitextview ×1
xcode ×1