Come si contrassegna un modello struct come amico?
Domanda
Ho un codice come questo:
template <typename T, typename U> struct MyStruct {
T aType;
U anotherType;
};
class IWantToBeFriendsWithMyStruct
{
friend struct MyStruct; //what is the correct syntax here ?
};
Qual è la sintassi corretta per dare amicizia al modello?
Soluzione
class IWantToBeFriendsWithMyStruct
{
template <typename T, typename U>
friend struct MyStruct;
};
Funziona in VS2008 e consente a MyStruct di accedere alla classe.
Altri suggerimenti
Secondo questo sito , la sintassi corretta sarebbe
class IWantToBeFriendsWithMyStruct
{
template <typename T, typename U> friend struct MyStruct;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow