!Changed title from '2D array for mixed types' to better reflect contents of this thread!
Hi again. Not sure if it belongs here, though i am a total newb.
I am trying to add a matrix of 6 columns and 34 rows with mixed types inside it. The format is constant, being:
1 2 3 4 5 6
|
col_1 col_2 col_3 col_4 col_5 col_6
row_1 string int double double double double
row_2...........................................
row_3...........................................
etc
row_34..........................................
|
What i found on the net is this (changed slightly to use my names and types)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
struct ForTableI
{
enum {is_int, is_double, is_string} type;
union
{
int ival;
double dval;
std::string sval;
}
val;
}
table_i[6][34];
table_i[0][0].type = is_string;
table_i[0][0].val.sval = Be;
|
My problems. Firstly, i am running into a use-of-deleted-function problem.
||=== Build: Release in Crystal (compiler: GNU GCC Compiler) ===|
(...)\Crystal\crystal_datainput.cpp|192|error: use of deleted function 'ForTableI::ForTableI()'|
(...)\Crystal\crystal_datainput.cpp|181|note: 'ForTableI::ForTableI()' is implicitly deleted because the default definition would be ill-formed:|
(...)\Crystal\crystal_datainput.cpp|181|error: use of deleted function 'ForTableI::<anonymous union>::<constructor>()'|
(...)\Crystal\crystal_datainput.cpp|185|note: 'ForTableI::<anonymous union>::<constructor>()' is implicitly deleted because the default definition would be ill-formed:|
(...)\Crystal\crystal_datainput.cpp|188|error: union member 'ForTableI::<anonymous union>::sval' with non-trivial 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
(...)\Crystal\crystal_datainput.cpp|181|error: use of deleted function 'ForTableI::<anonymous union>::~<constructor>()'|
(...)\Crystal\crystal_datainput.cpp|185|note: 'ForTableI::<anonymous union>::~<constructor>()' is implicitly deleted because the default definition would be ill-formed:|
(...)\Crystal\crystal_datainput.cpp|188|error: union member 'ForTableI::<anonymous union>::sval' with non-trivial 'std::basic_string<_CharT, _Traits, _Alloc>::~basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
(...)\Crystal\crystal_datainput.cpp|192|error: use of deleted function 'ForTableI::~ForTableI()'|
(...)\Crystal\crystal_datainput.cpp|181|note: 'ForTableI::~ForTableI()' is implicitly deleted because the default definition would be ill-formed:|
(...)\Crystal\crystal_datainput.cpp|181|error: use of deleted function 'ForTableI::<anonymous union>::~<constructor>()'|
(...)\Crystal\crystal_datainput.cpp|192|error: use of deleted function 'ForTableI::~ForTableI()'|
(...)\Crystal\crystal_datainput.cpp|193|error: expected unqualified-id before '{' token|
(...)\Crystal\crystal_datainput.cpp||In function 'void __static_initialization_and_destruction_0(int, int)':|
(...)\Crystal\crystal_datainput.cpp|192|error: use of deleted function 'ForTableI::~ForTableI()'|
(...)\Crystal\crystal_datainput.cpp||In function 'void __tcf_1()':|
(...)\Crystal\crystal_datainput.cpp|192|error: use of deleted function 'ForTableI::~ForTableI()'|
||=== Build failed: 11 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|
|
Not sure how to handle that.
Secondly, i do not know if this approach is correct.
The point of this is to be able to use a line (row) of variables as parameters for another function, except the string which will be a name that will call (point,define,specify) the rest.
Example:
1 2 3 4 5 6 7
|
std::string input;
std::cin >> input; //calling a specific row
...
magic
...
x = (&const so it doesnt copy everything all the time) table_i[0][1]+[0][2]*[0][3]+etc
return x;
|
and this will cause the rest (int and doubles) to be used as arguments elsewhere.
Writing this i am starting to think that i went overboard :/ But i need a way of doing this or something similar, as making 34 structs and 34 variations of functions using these arguments doesn't seem bright.
The general idea is this:
1 2 3 4
|
ask the user to choose material;
input of material;
lookup of material (int and doubles describe properties)
use properties in equation;
|