How can I send an declaration of the type that I am going to create using typedef?

For example, take this piece of code:

class Foo;
class Something {
    Foo *thing;
};
typedef std::vector<Something> Foo;

This does not compile because it is Fooalready a type on hit typedef. However, I think this shows my precedent; I have cyclic dependencies and need someone to execute another, but (for now) one of the things typedef'd. I would rather not write something like

class Foo {
    std::vector<Something> inside;
}

because then I need to remember insidein each my_foo.inside.some_method(). I would also like not to write a wrapper around std::vector<Something>because there would be many patterns.

, typedef?. ? ?

, : " typedef , ". : " typedef ".

+4
1

:

class Something;
typedef std::vector<Something> Foo;
class Something { Foo *thing; };

++ 11 , using typedef:

class Something;
using Foo = std::vector<Something>;
class Something { Foo *thing; };

.

+8

Source: https://habr.com/ru/post/1652106/


All Articles