كيف يمكنك وضع علامة على قالب البنية كصديق؟
سؤال
ولدي كود مثل هذا:
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;
}
لا تنتمي إلى StackOverflow