c++模板类作为友元类出现的问题
PHP中文网
PHP中文网 2017-04-17 12:59:50
0
1
556
#include <iostream>

using namespace std;

template <class T>
class SimNode
{
    friend SimSpace<T>;
private:
    T data;
    int link;
};

template <class T>
class SimSpace
{
private:
    SimNode<T>* space;
};

int main()
{
    system("pause");
    return 0;
}

报错之后问题出现在

friend SimSpace<T>;

请问为什么?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
Ty80

There is something wrong with your statement, it should be

class SimNode
{
    
private:
    template <class T>      //声明不要漏了template <class T>,这是C++很蛋疼的一个地方
    friend class SimSpace;  
    T data;
    int link;
};
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template