2008-10-15 14 views
10

मेरे पास इस तरह का कोड है:आप स्ट्रक्चर टेम्पलेट को मित्र के रूप में कैसे चिह्नित करते हैं?

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

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

टेम्पलेट को दोस्ती देने के लिए सही वाक्यविन्यास क्या है?

उत्तर

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

वीएस -2008 में काम करता है, और MyStruct कक्षा तक पहुंचने की अनुमति देता है।

+0

कूल! जो काम करता है (मैं अभी तक मतदान नहीं कर सकता, मैं पंजीकृत होने पर) – David

+0

ध्यान दें कि यह IWantToBeFriends को सभी प्रकार की MyStruct पहुंच प्रदान करता है, यह भी MyStruct पहुंच के विशिष्ट विशेषज्ञता प्रदान करना संभव है। –

+0

यह g ++ में भी काम करता है। –

7

this site के अनुसार, सही सिंटैक्स होगा

class IWantToBeFriendsWithMyStruct 
{ 
    template <typename T, typename U> friend struct MyStruct; 
} 
संबंधित मुद्दे

 संबंधित मुद्दे