How can I declare a pointer with filled information in C++?

Posted by chacham15 on Stack Overflow See other posts from Stack Overflow or by chacham15
Published on 2012-06-04T22:38:32Z Indexed on 2012/06/04 22:40 UTC
Read the original article Hit count: 162

Filed under:

typedef struct Pair_s {
    char *first;
    char *second;
} Pair;

Pair pairs[] = {
    {"foo", "bar"}, //this is fine
    {"bar", "baz"}
}; 

typedef struct PairOfPairs_s {
    Pair *first;
    Pair *second;
} PairOfPairs;

PairOfPairs pops[] = {
    {{"foo", "bar"}, {"bar", "baz"}}, //How can i create an equivalent of this NEATLY
    {&pairs[0], &pairs[1]} //this is not considered neat (imagine trying to read a list of 30 of these)
}; 

How can I achieve the above style declaration semantics?

© Stack Overflow or respective owner

Related posts about c++