#include <iostream>
class App;
void function(const char * function_name, int (App::* f)(int), App& obj)
{
(obj.*f)(5);
}
class App
{
public:
int y = 10;
int start(int x)
{
std::cout << x + y << std::endl;
return 1;
}
void exec()
{
function("111", &App::start, *this);
}
};
int main()
{
App app;
app.exec();
return 0;
}
(obj.*f)(5);
И то что в первом варианте конструктор у Poin будет вызван два раза, с 0,0 и с 100,100 - это нормально? Лишние вычисления как-никак
if (coords) {
coords->x = 100; coords->y = 100;
} else {
coords.reset(new Point(100, 100));
}
File& File::operator = (File&&)
(перемещение из временного объекта, новая фишка Си++11).class File {
public:
File& operator = (const File&) = delete; // Си++11
private:
File& operator = (const File&); // Си++03
}
using This = ...;
QThread eventThread;
EventHandler eventHandler;
QObject::connect(&eventThread, &QThread::started,
&eventHandler, &This::slotListenEvent);