سؤال

ولدي كود مثل هذا:

template <typename T, typename U> struct MyStruct {
    T aType;
    U anotherType;
};

class IWantToBeFriendsWithMyStruct
{
    friend struct MyStruct; //what is the correct syntax here ?
};

ما هي الجملة الصحيح لإعطاء الصداقة إلى القالب؟

هل كانت مفيدة؟

المحلول

class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U>
    friend struct MyStruct;
};

ويعمل في VS2008، ويسمح MyStruct للوصول إلى الطبقة.

نصائح أخرى

ووفقا ل هذا الموقع ، فإن الجملة الصحيح أن يكون

class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U> friend struct MyStruct; 
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top