Rest::function(char * function_name, int (App::* f)(String), App& object)
// вместо App можно какой-то интерфейс, который App реализует
…
object.*f("string");
...
bt_rest.function("", &App::startManufacturing, *this);
class App {
static int startManufacturing(String command)
};
Rest::function(char * function_name, int (*f)(String, void*), void*);
void doStartManufacturing(String command, void* closure) {
reinterpret_cast<App*>(closure)->startManufacturing(command);
}
...
bt_rest.function("startManufacturing", doStartManufacturing, this);
App app;
int doStartManufacturing(String command) { return app.startManufacturing(command); }
...
bt_rest.function("startManufacturing", doStartManufacturing);
class ComparatorBase
{
public:
virtual ~ComparatorBase() = default;
};
class Comparator : public ComparatorBase {
public:
virtual int compare(Comparator *t)=0;
};
class User : public Comparator{
public:
int compare(ComparatorBase *u) override {
return 1;
}
};
class Father
{
public:
virtual Father& foo();
virtual ~Father() = default;
};
class Son : public Father
{
public:
Son& foo() override;
};
int User::compare(Comparator *u)
{
auto* v = dynamic_cast<User*>(u);
if (!v)
return false;
return v->name > this->name;
}
template <class T>
class Comparator {
public:
virtual int compare(T *t)=0;
virtual ~Comparator() = default;
};
class User : public Comparator<User> {
private:
std::string name;
public:
User(std::string name){this->name=name;}
int compare(User *u);
void showName(){std::cout<<"Name "<<this->name<<std::endl;}
};
int User::compare(User *u)
{
return u->name > this->name;
}
center_pt = *new Point(x/size, y/size);
center_pt = Point(x/size, y/size);
class Geolocator {
public:
Point coords;
bool isReliable;
Geolocator() : coords(0,0), isReliable(false) {}
void getFromSensor() {
coords = Point(100, 100);
isReliable = true;
}
};
class Geolocator {
public:
std::unique_ptr<Point> coords;
void getFromSensor() {
Point pt(100, 100);
if (coords) {
*coords = pt;
} else {
coords.reset(new Point(pt));
}
// а если и операции = у Point нет, то можно
// coords.reset(new Point(100, 100));
}
void declareUnreliable() {
coords.reset();
}
};
bool isPreciseFloat(unsigned long long n)
{
// Простейшая проверка: стираем нижние 24 бита
// Если в них вписываемся — ДА.
unsigned long long n1 = n & ~((1ULL << 24) - 1);
if (n1 == 0)
return true;
// Получаем верхнюю единицу
// (можно также двоичным поиском, но я этого с листа не напишу)
while (true) {
unsigned long long n2 = n1 & (n1 - 1);
if (n2 == 0)
break;
n1 = n2;
}
// Получаем маску всего, что ниже 23 бит от верхнего бита.
n1 >>= 23;
--n1;
// Проверяем по маске
return (n & n1) == 0;
}
99900000000000
+ 1,00
-----------------
9990 → 9,99e13
99900000000000
+ 50000000000
-----------------
9995 → 1,00e14 → переполнение
QApplication a(argc, argv);
FmAutoriz au;
std::unique_ptr<SomeConnection> connection = au.exec(); // SomeConnection и exec придётся написать
if (connection) {
FmMain m(connection);
m.show();
return a.exec();
} else {
return 0;
}
std::unique_ptr<SomeConnection>FmAutoriz::exec()
{
bool b = QDialog::exec();
if (b) {
return std::move(this->connection);
// connection — поле FmAutoriz.
// Такой же unique_ptr, в обработчиках кнопок пытаемся создать соединение.
} else {
return nullptr;
}
}
void FmAutorize_on_btOk_click()
{
connection = new SomeConnection();
if (connection.connect(someLogin, somePassword)) {
accept();
} else {
// сообщи об ошибке
}
}
QHeaderView* header = ui->tableView->verticalHeader();
QWidget* viewport = header->viewport();
int i1 = header->logicalIndexAt(0);
int i2 = header->logicalIndexAt(viewport->height() - 1);
if (i2 < 0)
i2 = header->count() - 1;
QString s = QString::number(i1) + " - " + QString::number(i2);
ui->lbResult->setText(s);
return m_tableView->viewport()->height() / m_tableView->rowHeight(0);
(rbv<false, true, true> << 1) + false
.(rbv<true, true> << 1) + false
.(rbv<true> << 1) + true
.