خرید بک لینک

The following code snipped defines a nested chain of templated C++ classes. The problem I have starts on the third level. The initialization of the three level nested class works well, which can easily checked in a debugger.

However, a problem arises when attempting to access the nested class member variables aValue.

While the first two levels work well, accessing third level aValue gives me no joy.

Any suggestions on how to propagate variable access down the chain?

Ideally, is there any iterator available for a looped access?

template <typename T, typename Tail> // Tail will be a UnionNode too.
struct UnionNode : public Tail {
    T aValue ;
    template<typename U> struct inUnion {
        typedef typename Tail::template inUnion<U> dummy;
    };
};

template <typename T> // For the last node Tn.
struct UnionNode<T, void> {
    T aValue ;
};

void AnotherTest() {

    // definition and initialization OK. Confirmed in Debugger.
    UnionNode<int, UnionNode<float, UnionNode<char,void>>> aNode {'c', 3.14, 10};

    // no problem
    int   *i_aValue = &aNode.aValue;

    // no problem
    float *f_aValue = &aNode.UnionNode<float, UnionNode<char,void>>::aValue;

    // this does not compile
    char  *c_aValue = &aNode.UnionNode<float, UnionNode<char,void>>.UnionNode<char,void>::aValue;

    // nor does this compile
    char  *c_aValue = &aNode.UnionNode<float, UnionNode<char,void>>::UnionNode<char,void>::aValue;


    *i_aValue = 100;    // OK
    *f_aValue = 2.78;   // OK
}

برچسب: نویسنده: استخدام کار تاريخ: شنبه 7 شهريور 1405 ساعت: 2:40

صفحه بندی