小编Adr*_*ian的帖子

将默认构造的迭代器与operator ==进行比较

C++标准是否说我应该能够比较两个默认构造的STL迭代器是否相等?默认构造的迭代器是否具有可比性?

我想要以下,使用std :: list作为例子:

void foo(const std::list<int>::iterator iter) {
    if (iter == std::list<int>::iterator()) {
        // Something
    }
}

std::list<int>::iterator i;
foo(i);
Run Code Online (Sandbox Code Playgroud)

我想要的是迭代器的NULL值,但我不确定它是否合法.在Visual Studio 2008附带的STL实现中,它们在std :: list的operator ==()中包含断言以排除此用法.(他们检查每个迭代器是否由同一个容器"拥有",并且默认构造的迭代器没有容器.)这暗示它不合法,或者可能是他们过于热心.

c++ iterator stl visual-studio-2008

11
推荐指数
2
解决办法
2193
查看次数

"缺少非虚拟thunk"和继承顺序

我们在C++中有一个很大的代码库,在一个小的重构(一个类添加并重写了一些相关的方法)之后,我们开始在GCC 3和4上获得链接器错误.链接器错误特别是"缺少对非虚拟thunk的引用"在我们的大型SDK中继承类的小型示例程序.

搜索网络并没有提供许多暗示,除了一些似乎已经解决的旧GCC错误之外.

问题的属性似乎是:

  • GCC 3.4.6和4.3.3优化 -O2
  • 多重继承,包括偶尔的虚拟继承.
  • 从比如说更改继承顺序,
    class Foo: public A, public B {}
    class Foo: public B, public A {}
    对缺少的thunk类"修复"的问题.

虚拟继承仅出现在一个非常常用的基类中,用于引用计数.我已经证实,这个类的每个用法都是虚拟公共的,而不仅仅是公共继承.

显然,摆弄继承顺序并不能解决问题.还有什么呢?

c++ gcc thunk

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

UIAlertController的popover变形了

我正在使用UIToolbar中的UIAlertController向用户提供一个选项列表,其中包含一个首选的操作表样式.呈现时,弹出箭头被切掉,其角落呈圆形,有两个不同的半径:

变形的UIAlertController弹出窗口

我用来呈现它的代码直接来自文档,据我所知:

UIAlertController *alertController =
    [UIAlertController alertControllerWithTitle:@""
                                        message:@""
                                 preferredStyle:UIAlertControllerStyleActionSheet];
NSArray *actions = @[
    [UIAlertAction actionWithTitle:@"Take a Photo"
                             style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction *action) {}],
    [UIAlertAction actionWithTitle:@"Choose from Album"
                             style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction *action) {}],
    [UIAlertAction actionWithTitle:@"Cancel"
                             style:UIAlertActionStyleCancel
                           handler:^(UIAlertAction *action) {}]
];
for (UIAlertAction *action in actions) {
    [alertController addAction:action];
}

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    alertController.modalPresentationStyle = UIModalPresentationPopover;
    alertController.popoverPresentationController.barButtonItem = myBarButtonItem;
}
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

这是一个已知的错误?我在iOS 8.2和iOS 8.1和8.2上的模拟器上尝试过物理iPad.

uipopovercontroller ios ios8 uialertcontroller

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

在C中包装C++:派生到基本转换

我将一个简单的C++继承层次结构包装成"面向对象的"C.我试图弄清楚是否有任何问题将C++对象的指针视为指向不透明C结构的指针.特别是,在什么情况下派生到基础的转换会导致问题?

类本身相对复杂,但层次结构很浅并且仅使用单继承:

// A base class with lots of important shared functionality
class Base {
    public:
    virtual void someOperation();
    // More operations...

    private:
    // Data...
};

// One of several derived classes
class FirstDerived: public Base {
    public:
    virtual void someOperation();
    // More operations...

    private:
    // More data...
};

// More derived classes of Base..
Run Code Online (Sandbox Code Playgroud)

我计划通过以下相当标准的面向对象的C向C客户端展示它:

// An opaque pointers to the types
typedef struct base_t base_t;
typedef struct first_derived_t first_derived_t;

void base_some_operation(base_t* object) {
     Base* base = (Base*) object; …
Run Code Online (Sandbox Code Playgroud)

c c++ oop standard-layout

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