Storing a type in C++

后端 未结 8 1440
春和景丽
春和景丽 2020-12-05 17:41

Is it possible to store a type name as a C++ variable? For example, like this:

type my_type = int; // or string, or Foo, or any other type
void* data = ...;
         


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 17:54

    Yes, if you code it yourself.

    enum Foo_Type{
        AFOO,
        B_AFOO,
        C_AFOO,
        RUN
    };
    
    struct MyFoo{
        Foo_Type m_type;
        Boost::shared_ptr m_foo;
    }
    

    as commented below, what I left out was that all these "foo" types would have to be related to Foo. Foo would, in essence, be your interface.

提交回复
热议问题