Jul 20, 2014 at 1:38pm UTC
No, you can't introduce new types in type specifiers in C++, this isn't C.
you can make std::vector<std::array<int , 3>> things;
or std::vector<std::tuple<int , int , int >> things;
Jul 20, 2014 at 2:07pm UTC
... What, can you do it in C?
I'm talking about a struct with various elements, whether they be data types or classes, not std::tuple or std::pair.
Jul 20, 2014 at 3:18pm UTC
in C, you can sneak in struct declarations in any type specifier, although it's not always meaningful, but it compiles: struct {int x;} f(struct {int y;} a);
In C++, if you need a struct, define it as such (at most, you can define objects, pointers/references to, and C-style arrays of it on the same line)
Jul 20, 2014 at 4:33pm UTC
Does C++ even support anonymous structures? I think only certain compilers have it as an extra feature.
Jul 20, 2014 at 6:00pm UTC
Unnamed structures, yes of course:
1 2 3 4 5 6
// C++98
struct { int x;} a;
int main()
{
a.x = 1;
}
Anonymous structures - no, they are a C11 feature:
1 2 3 4 5 6 7 8
// C11
int main(void )
{
struct { // unnamed
struct { int i, j; }; // anonymous
} v1;
v1.i = 2;
}
Last edited on Jul 20, 2014 at 6:06pm UTC
Jul 20, 2014 at 6:49pm UTC
Is there no way to use an unnamed structure in a vector or map?
Jul 20, 2014 at 7:59pm UTC
Thank you! This is exactly what I was looking for!