Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 如何在C++;11_C++11 - Fatal编程技术网

C++11 如何在C++;11

C++11 如何在C++;11,c++11,C++11,如果我从第三方代码中获得以下代码: template <typename T> class MemberType { public: using const_ptr = const T*; }; struct SchemaA { MemberType<int> *m_1; MemberType<double> *m_2; // more data members that I don't care for Membe

如果我从第三方代码中获得以下代码:

template <typename T>
class MemberType
{
public:
    using const_ptr = const T*;
};

struct SchemaA
{
    MemberType<int> *m_1;
    MemberType<double> *m_2;

    // more data members that I don't care for
    MemberType<double> *m_3;
    MemberType<double> *m_4;
};

struct SchemaB
{
    MemberType<string> *m_1;
    MemberType<vector<int>> *m_2;

    // more data members that I don't care for
    MemberType<string> *m_3;
    MemberType<vector<int>> *m_4;
};

可以使用类型特征修改类型,如下所示:

template <typename TSchema>
class MySchema
{
public:
    MySchema(TSchema *schema)
        : m_schema(schema)
    {
        m_1 = schema->m_1;
        m_2 = schema->m_2;
    }

public:
    decltype(TSchema::m_1) m_1;
    decltype(TSchema::m_1) m_2;

private:
    TSchema *m_schema;
};
std::remove_pointer<decltype(decltype(my_schema)::m_1)>::type::const_ptr
std::remove\u pointer::type::const\u ptr

当然,如果您可以控制所涉及的类和类模板,那么最好提供嵌套类型名称,以消除对所有
decltype
s的需要。

您需要使用更多
decltype
,或者:

std::remove_pointer_t<decltype(my_schema.m_1)>::const_pt‌​r
std::删除指针\u t::常量\u pt‌​R

classmyschema
{
使用m_1_type=std::remove_pointer\t;
使用m_2_type=std::remove_pointer\t;
m_1_类型*m_1;
m_2_类型*m_2;
//其他现有定义
};
MySchema::m_1_type/*用法*/

std::remove_pointer::type::const_ptr
?@VittorioRomeo是的,当然也可以。
my_schema::m1::const_ptr
std::remove_pointer<decltype(decltype(my_schema)::m_1)>::type::const_ptr
std::remove_pointer_t<decltype(my_schema.m_1)>::const_pt‌​r
class MySchema 
{
    using m_1_type = std::remove_pointer_t<decltype(TSchema::m_1)>;
    using m_2_type = std::remove_pointer_t<decltype(TSchema::m_2)>;

    m_1_type * m_1;
    m_2_type * m_2;

    // other existing definitions
};

MySchema<SchemaA>::m_1_type /* usage */