B
B
bullock2016-07-27 16:52:02
Programming
bullock, 2016-07-27 16:52:02

Table with different data types in c++, how to create?

How to create table data type in c++? The number of columns and their type are unknown in advance, the number of rows is also unknown.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
maaGames, 2016-07-27
@maaGames

boost::variant or equivalent. void* + type descriptor. qt+qml. There are many options. Most likely you did not understand the task correctly or you are looking for the wrong solution for it. In the end, you can connect the database or serialize and store each cell as strings, with deserialization in the place where the type is already known. Lots of options...

M
mikhail_404, 2016-07-28
@mikhail_404

Most likely, it is possible to combine objects under one logic, i.e. create a pointer to the base class Base* and store a matrix of such pointers, and then work with all objects through their common methods (in a simple way).

std::vector <std::vector <Base*>> matrix(n, std::vector <Base*>(m));
for(size_t i = 0; i < n; ++i)
    for(size_t j = 0; j < m; ++j)
        matrix[i][j]->doSmth();

A
Alexander Titov, 2016-07-28
@alex-t

Already mentioned boost::variant, if a list of possible types is defined, it is convenient to organize general operations in boost::variant by specifying them for each type.
If the type is not known at all - boost::any (but this happens very rarely).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question