| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 823 人关注过本帖
标题:麻烦各位,问个问题
取消只看楼主 加入收藏
cavinlu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-9-24
收藏
 问题点数:0 回复次数:2 
麻烦各位,问个问题

在一个模板类内部说明另一个类是这个类的友元,

如下写法是否正确?

#include<iostream.h> #define MaxVertexes 20 template <class vertexType,class arcType> class Graph;

template <class arcType> class ArcNode{ friend class Graph<class vertexType,class arcType>; private: int adjvex; arcType weight; ArcNode<arcType>*nextarc; public: ArcNode(){} ArcNode(int v,arcType w):adjvex(v),weight(w),nextarc(NULL){} }; template <class vertexType,class arcType> class VertexNode{ friend class Graph <class vertexType,class arcType>; private: vertexType data; ArcNode<arcType>*firstarc; public: VertexNode(){} VertexNode(vertexType v):data(v),firstarc(NULL){} };

我想说明ArcNode和VertexNode为Graph的友元,

friend class Graph<class vertexType,class arcType>;

这句话的下划线的class要不要加,以前都是不加的,编译能通过的,这次老是说有个错误!

如果不加class,两处加下划线和加粗的地方都去掉的话,编译器报如下错误:

Compiling... Graph.cpp F:\tmp\Graph\Graph.cpp(5) : error C2065: 'vertexType' : undeclared identifier F:\tmp\Graph\Graph.cpp(13) : see reference to class template instantiation 'ArcNode<arcType>' being compiled Error executing cl.exe.

Graph.obj - 1 error(s), 0 warning(s)

请问这种格式对吗?class要加吗?

搜索更多相关主题的帖子: class arcType ArcNode Graph 麻烦 
2005-09-24 21:27
cavinlu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-9-24
收藏
得分:0 
版主,能否就我写的程序,编译器的错误给我说说原因?

                                                                                                   多谢了!
2005-09-25 15:17
cavinlu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-9-24
收藏
得分:0 
版主,帮我看看这段程序,谢谢!
版主,能否帮我看看我的程序,我按你的做了,可编译还是通不过,晕啊!
kb6naqoE.rar (8.39 KB) 麻烦各位,问个问题

2005-09-25 16:54
快速回复:麻烦各位,问个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013905 second(s), 9 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved