Organizing Data Project

Is there a way to give Variables Subvariables? e.g. dataobject.animals.horse.width ?

I was thinking about inheriting classes e.g. horse_class is inherited by animal_class with the variable width but then you would access it

dataobject.width

and that is not what i am looking for. Is there a way to do this? Thx friends.

What you're describing (I think) you can achieve with run-of-the-mill OO coding.
A non-static member object of (the class of) the variable could be called a 'subvariable'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

struct horse_t { std::string colour = "dark bay" ; /* .. */ };
struct cat_t { double weight = 3.5 ; /* .. */ };
struct animals_t { horse_t horse ; cat_t cat ;/* .. */ };

struct data_object_t { animals_t animals ; /* .. */ };

int main()
{
    data_object_t data_object ;
    std::cout << data_object.animals.horse.colour << '\n'
              << data_object.animals.cat.weight << '\n' ;
}
Topic archived. No new replies allowed.