extern "C"
, и часто его применяют, например, при экспорте в межъязыковой DLL, при интеграции Си-кода с Си++. Что в Ди, не знаю.class Res
{
public:
Res() = default;
Res(MYSQL_RES* x) : fD(x) {}
Res(const Res&) = delete;
Res(Res&& x) { operator = (std::move(x)); }
Res& operator = (const Res& x) = delete;
Res& operator = (Res&& x);
~Res() { close(); }
const MYSQL_RES& d() { return *fD; }
void close();
bool next();
std::wstring tableName() const;
const char* at(size_t i) const { return fRw[i]; }
private:
MYSQL_RES* fD = nullptr;
MYSQL_ROW fRw = nullptr;
};
Obj* p = new Obj;
…
delete obj;
u_p<Obj> p { new Obj };
// И делай с ним что хочешь, удалится автоматически
u_p<ImportIssues> getImportIssues();
class Father{
public:
virtual ~Father();
};
class Son : public Father{};
class AnotherSon : public Father{};
u_p<Father> someObj { new Son };
std::vector<std::unique_ptr<QThread>> backJobs;
typedef bool SymbolBoolMap[16][15];
static SymbolBoolMap symbol_Bool_Map_English_Upper_A = { ... };
[const] SymbolBoolMap&
.SELECT * FROM orders
INNER JOIN projects AS pf ON pf.project_id = orders.order_from
INNER JOIN projects AS pt ON pt.project_id = orders.order_to
#include <iostream>
template <class T>
struct Array
{
const size_t size;
const T* const data;
const T* begin() const { return data; }
const T* end() const { return data + size; }
constexpr Array(const std::initializer_list<T>& x)
: size(x.size()), data(x.begin()) {}
};
using Row = Array<int>;
using Matrix = Array<Row>;
Matrix mtx = {
{1, 2, 3 },
{ 10, 20, 30, 40, 50 },
{},
{ 100 }
};
int main()
{
for (auto& u : mtx) {
for (auto& v : u) {
std::cout << v << ' ';
}
std::cout << std::endl;
}
return 0;
}
#include <iostream>
// Изменяемый вариант
template <class T>
struct Array2
{
const size_t size;
T* const data;
T* begin() { return data; }
T* end() { return data + size; }
const T* begin() const { return data; }
const T* end() const { return data + size; }
T& operator[](int i) { return data[i]; }
template <size_t N>
constexpr Array2(T (&x)[N])
: size(N), data(x) {}
};
using Row2 = Array2<int>;
using Matrix2 = Array2<Row2>;
int main()
{
int i;
std::cin >> i;
int row1[] = { 1, i, 3 };
int row2[] = { 10, 2*i, 30, 3*i, 50 };
int row3[] = { 13 };
int row4[] = { 100 };
Row2 mtx[] = { row1, row2, row3, row4 };
mtx[1][4] = i * 6;
for (auto& u : mtx) {
for (auto& v : u) {
std::cout << v << ' ';
}
std::cout << std::endl;
}
return 0;
}