@Avazart
7566 / 5551 / 326
Регистрация: 10.12.2010
Сообщений: 24,838
|
19.08.2016, 13:44
|
|

Сообщение от isrepeat
ra3y, использовать дополнительные фигурные скобки не хочется. хочется так как в последнем
main.
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| #include <iostream>
#include <vector>
class Row
{
public:
Row(std::size_t size=0)
:cols_(size){};
int& operator[](int index) { return cols_[index]; }
const int& operator[](int index) const { return cols_[index]; }
private:
std::vector<int> cols_; // или std::array<> или просто обычный массив.
};
class Matrix
{
public:
Matrix(std::size_t rowSize, std::size_t colSize)
:rows_(rowSize, Row(colSize) ){}
Row& operator[](int index) { return rows_[index]; }
const Row& operator[](int index)const { return rows_[index]; }
private:
std::size_t colSize_;
std::vector<Row> rows_;
};
int main()
{
Matrix m(3,4);
m[2][2]= 5;
std::cout<< m[2][2] << std::endl;
return 0;
} |
|
http://ideone.com/0beYw8
0
|