小编szy*_*zym的帖子

C++:通过指针调用成员函数

我有这个使用指向成员函数的示例代码,我想在运行时更改它,但我无法使其工作.我已经试过了this->*_currentPtr(4,5) (*this)._currentPtr(4, 5).在同一个类中调用指向方法的正确方法是什么?

错误:表达式必须具有(指针指向)函数类型

#include <iostream>
#include <cstdlib>

class A {

public:

    void setPtr(int v);
    void useFoo();

private:
    typedef int (A::*fooPtr)(int a, int b);

    fooPtr _currentPtr;

    int foo1(int a, int b);
    int foo2(int a, int b);
};

void A::setPtr(int v){
    if(v == 1){
        _currentPtr = foo1;
    } else {
        _currentPtr = foo2;
    }
}

void A::useFoo(){

    //std::cout << this->*_currentPtr(4,5); // ERROR
}

int A::foo1(int a, int b){
    return a - b;
}

int A::foo2(int a, int b){ …
Run Code Online (Sandbox Code Playgroud)

c++ function-pointers

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

为什么 google 测试 ASSERT_FALSE 在方法中不起作用但 EXPECT_FALSE 起作用

无论是ASSERT_TRUEASSERT_FALSE不在编译LibraryTest与错误类。

错误 C2664:“std::basic_string<_Elem,_Traits,_Alloc>::basic_string(const std::basic_string<_Elem,_Traits,_Alloc> &)”:无法将参数 1 从“void”转换为“const std::basic_string” <_Elem,_Traits,_Alloc> &'

它在TEST_F我使用的任何地方都有效。但是在类和方法中EXPECT_FALSE编译都很好。LibraryTestTEST_F

如何ASSERT在 a使用的方法中使用TEST_F

class LibraryTest : public ::testing::Test
{
public:
    string create_library(string libName)
    {
        string libPath = setup_library_file(libName);

        LibraryBrowser::reload_models();

        ASSERT_FALSE(library_exists_at_path(libPath));
        new_library(libName, libPath);
        ASSERT_TRUE(library_exists_at_path(libPath));
        EXPECT_FALSE(library_exists_at_path(libPath));
        return libPath;
    }
};

TEST_F(LibraryTest, libraries_changed)
{
    string libName = "1xEVTestLibrary";
    string libPath = create_library(libName);
}
Run Code Online (Sandbox Code Playgroud)

c++ googletest

6
推荐指数
2
解决办法
5276
查看次数

ARC焊机中有哪些"附加元数据"键

我正在寻找ARC Welder中"Additional Metadata"字段的参考文档.

这里和那里(也SO),我可以看到答案提的特定键(如resize,formFactor,enableExternalDirectory,usePlayServices),但文件没有提及.有没有?

google-chrome-arc

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

Tkinter代码在Windows上运行,但在Linux上运行

我在windows中编写了这段代码,但是当我将它复制到我的raspberry pi(运行Jessie Debian)时,它会给出运行时错误

我的代码:

from Tkinter import *
from PIL import ImageTk,Image
from time import sleep
import thread
root = Tk()
img=ImageTk.PhotoImage(Image.open("1.jpg").resize((root.winfo_screenwidth()-3,root.winfo_screenheight()-3)))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
if __name__ == '__main__':
    thread.start_new_thread(root.mainloop,())
    for i in xrange(1,5):
        sleep(1)
        img2 = ImageTk.PhotoImage(Image.open(str(i)+".jpg").resize((root.winfo_screenwidth()-3,root.winfo_screenheight()-3)))
        panel.configure(image = img2)
        panel.image = img2
Run Code Online (Sandbox Code Playgroud)

在linux中执行时会出错:

Unhandled exception in thread started by <bound method Tk.mainloop of <Tkinter.Tk instance at 0x75b605d0>>
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1124, …
Run Code Online (Sandbox Code Playgroud)

python linux tkinter python-multithreading

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