小编jbl*_*ixr的帖子

9
推荐指数
2
解决办法
6541
查看次数

CGAffineTransform 仅缩放宽度和高度

如何在不影响其原点的情况下缩放 CGontext,即仅缩放宽度和高度?如果我直接使用像下面这样的比例,它也会缩放原点。

context.scaledBy(x: 2.0, y: 2.0)

有没有办法构造一个 AffineTransform 来操纵宽度和高度,而不影响原点?

我想要一个可以同时用于CGContext和 的AffineTransform CGRect

例如一个CGRect rect = {x, y, w, h}

var t = CGAffineTransform.identity
t = t.scaledBy(x: sx, y: sy)
let tRect = rect.applying(t)
Run Code Online (Sandbox Code Playgroud)

tRect{x * sx, y * sy, w * sx, h * sy}

但我想要{x, y, w * sx, h * sy}。虽然可以通过计算来实现,但我需要 CGAffineTransform 来做到这一点。

core-graphics foundation ios swift

5
推荐指数
1
解决办法
3567
查看次数

计算将 n 划分为正整数之和的方法数 c++

我需要编写函数作为赋值的一部分..\n我需要计算将 n 划分为正整数之和的方法数,但我不能使用 while 或 goto

\n\n
/*\n * REQUIRES: n > 0\n * EFFECTS: computes the number of ways to partition n into the sum of\n *          positive integers\n * MUST be tree recursive\n * Hint: Use a helper function that computes the number of ways to\n * partition n using a bounded subset of integers. Then use logic\n * similar to count_change() from lecture to divide partitions into\n * those that use a specific item and those that …
Run Code Online (Sandbox Code Playgroud)

c++ recursion

3
推荐指数
1
解决办法
3628
查看次数

C++:为什么volatile访问需要排序?

我在C++测验网站上浏览了下面的代码.它还提供了解释.我知道volatile限定符向编译器发出信号,表明变量的值可能会被其他一些因素改变.该网站的解释补充说,volatile应该对访问进行排序.为什么以及如何排序?

我不明白他们的意思是无序的副作用标量对象.还请说清楚.

#include <iostream>
volatile int a;
int main() {
  std::cout << (a + a);
}
Run Code Online (Sandbox Code Playgroud)

这里的问题不是缺少变量的初始值设定项a- 它将在这里隐式初始化为0.但问题是在访问之间没有排序的情况下访问两次.根据§1.912,glvalues的访问volatile是副作用,根据§1.915,这两个对同一标量对象的未测序副作用会导致未定义的行为.

c++ volatile

3
推荐指数
1
解决办法
197
查看次数

UnsafeMutablePointer到Array元素

var a = [1,2,3]
let ptr1 = UnsafeMutablePointer<Int>(&a[0]) //works fine

let index = 0
let ptr2 = UnsafeMutablePointer<Int>(&a[index]) //compiler throws error
Run Code Online (Sandbox Code Playgroud)

error:无法为类型UnsafeMutablePointer<Int>为参数列表的类型调用初始值设定项(inout Int)

为什么后者不编译?这里有什么我想念的吗?


我想做一个下面的片段.

class Holder {
    var numbers: [Int] = [1,2,3,4]
    var modifier: Modifier

    init(index: Int) {
       self.modifier = Modifier(UnsafeMutablePointer(&self.numbers) + index)
    }

}

class Modifer {
  var ptr: UnsafeMutablePointer<Int>

  init(_ ptr: UnsafeMutablePointer<Int>) {
     self.ptr = ptr
  }

  func change(to: Int) {
     self.ptr.pointee = to
    // expected the change to be reflected in numbers array …
Run Code Online (Sandbox Code Playgroud)

macos ios swift unsafemutablepointer

2
推荐指数
1
解决办法
691
查看次数

嵌套类.error:期望的参数声明符 - 用于内部类实例

我开始学习C++中的嵌套类,我尝试了一个快速代码,我粘贴在这里看看嵌套类是如何工作的.但编译以一些我无法弄清楚的错误结束.

文件:check.cpp

class Outside{
    public:
        class Inside{
            private:
                int mInside;
            public:
                Inside(const int& x):mInside(x){}
        };
    private:
        Inside mOutside(20);
};

int main(void){
Outside o;
return 0;
}
Run Code Online (Sandbox Code Playgroud)

我编译的错误 g++ -Wall -std=c++11 -o check.out check.cpp

check.cpp:12:25: error: expected parameter declarator
        Inside mOutside(20);
                        ^
check.cpp:12:25: error: expected ')'
check.cpp:12:24: note: to match this '('
        Inside mOutside(20);
                       ^
Run Code Online (Sandbox Code Playgroud)

我需要在此错误背后提供一个很好的解释以及如何克服此错误.

c++ member-initialization c++11

1
推荐指数
1
解决办法
4522
查看次数