100fen~~~easy prob

zhenming_liu 2003-02-14 07:12:23
详情: http://ihome.ust.hk/~cs_lzm/prob

好象不认我的friend function:(
原来以为是operator的问题, 但是改用一般函数后亦未能解决

望赐教
...全文
44 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinajiji 2003-02-14
  • 打赏
  • 举报
回复
zhenming_liu() :
请问你这个头衔是什么啊?
He is also a member of HKUST International Collegiate Programming Contest Team.
请给我多加点分啊!谢谢!
zhenming_liu 2003-02-14
  • 打赏
  • 举报
回复
可以了, 解决了~~~
谢谢~
chinajiji 2003-02-14
  • 打赏
  • 举报
回复
你的源程序太长!!!这里贴不出来!!!!!!!!!
chinajiji 2003-02-14
  • 打赏
  • 举报
回复
你的源程序太长,我不好一一细看,仅就语法问题做了修改,在DEV-c++ 4.9.7.0(用的是GCC3.21编译器)上通过,仅你参考:

/////////////////////////////////////////////////////////////////////////////////////////////////
// (C)Copyright 2002-2003 Liu ZhenMing(cs_lzm) //
// All Right Reserved //
// Computer Science Department //
// HongKong University of Science and Technology //
// //
//Redistrubution and use in source (source code> and binary(object code) forms, with or without//
//modification after Feb. 21st are permitted provided that the following conditions are met: //
//1. Redistrubuted source code must retain the above copyright notice, this list of conditions //
// and the disclaimer below //
//2. Redistributed object code must reproduce the above copyright notice, this list of //
//conditions in the documentation and the disclaimer below and/or other material provided with //
// the distrubution //
//3. Redistribution of any modified code must be labeled //
// //
//THIS SOURCE CODE IS ONE POSSIBLE SOLUTION FOR THE COMP171(2003 SPRING) PROGRAMMING ASSIGNMENT//
//1A. LIU ZHENMING DOES NOT WARRANT THAT THE OPERATIONS/FUNCTIONS/CLASSES CONTAINTED IN THIS //
//SOURCE WILL MEET THE USER'S REQUIREMENTS AND HE IS UNDER NO OBLIGATION TO MAINTAIN, CORRECT, //
//UPDATE, CHANGE, MODIFY, OR OTHERWISE SUPPORT THIS SOURCE FILE //
// //
// NO USAGE OF THIS SOURCE(SOURCE CODE) IS PERMITTED BEFORE FEB 21ST 2003 //
// //
/////////////////////////////////////////////////////////////////////////////////////////////////



#include <iostream>
#include <fstream>

using namespace std;

//#define DEBUG_LISTNODE_T
#define DEBUG_LISTITR_T
#define DEBUG_LIST_T


////////////////////The define of List, ListItr, ListNode////////////////////

//The basic elements inside a polynomial, including the co-eficient and the exponent
//coefficient type can be of template
template <class COEF_T>
class Poly_Elem_T
{public:
COEF_T _ce;
int _exp;

Poly_Elem_T(const COEF_T& input_ce = COEF_T(), int input_exp = 0)
: _ce(input_ce), _exp(input_exp) { }

bool operator==(const Poly_Elem_T& rhs);
bool operator!=(const Poly_Elem_T& rhs);

#ifdef VISUAL_C
friend ostream& operator<<(ostream& os, const Poly_Elem_T<COEF_T>& rhs);
#endif

friend void Output<COEF_T>(const Poly_Elem_T<COEF_T>& rhs, ostream& os );
};

template <class Entry_T>
class List_T;

template <class Entry_T>
class ListItr_T;

template <class COEF_T>
class Polynomial_T;

template <class Entry_T>
class ListNode_T
{
//Function Area
#ifdef DEBUG_LISTNODE_T
//Make the constructor available universally accessable during the debug
public:

#endif

ListNode_T(const Entry_T& theElem = Entry_T(), ListNode_T* nextNode = NULL)
: _elem(theElem), _next(nextNode) { }

private:
//Data Area
Entry_T _elem;
ListNode_T* _next;

friend class List_T<Entry_T>;
friend class ListItr_T<Entry_T>;

//Functions for debug
#ifdef DEBUG_LISTNODE_T
public:
Entry_T& GetElem() { return _elem; }
void SetElem(const Entry_T& val, ListNode_T* nextNode) { _elem = val; _next = nextNode;}
void Output();
#endif
};
chinajiji 2003-02-14
  • 打赏
  • 举报
回复
仅就你给出的这个例子而言,可以这样修改:

#include <iostream>
#include <stdlib.h>
using namespace std;

template <class Type>
class _T
{
friend void Output<Type>(_T<Type> t);
private:
Type p;
public:
_T():p(10){}
Type getp() const { return p;}
};

template <class Type>
void Output(_T<Type> t)
{
cout << t.p << endl;
}

int main(int argc, char *argv[])
{
_T<int> t;
Output(t);
system("PAUSE");
return 0;
}

我在DEV-C++ 4.9.7.0(用的是gcc3.21编译器)中的运行结果是:
10
请按任意键继续 . . .
zhenming_liu 2003-02-14
  • 打赏
  • 举报
回复
附上错误信息:

[Linker error] undefined reference to `Output(_T<int>)'
zhenming_liu 2003-02-14
  • 打赏
  • 举报
回复
那就简短点:


#include <iostream>

using namespace std;

template <class Type>
class _T
{

friend void Output(_T t);
private:
Type p;
public:
_T():p(10){}
};

template <class Type>
void Output(_T<Type> t)
{
cout << t.p << endl;
}

int main()
{
_T<int> t;
Output(t);

return 0;
}

错哪,怎么该?
chinajiji 2003-02-14
  • 打赏
  • 举报
回复
Zhen Ming Liu (HKUST Undergraduate Student 2001-now)




--------------------------------------------------------------------------------

Mr. Liu Zhen Ming is a full time Under-graduate student in the Department of Computer Science, at Hong Kong University of Science and Tech. Before joining UST, he was a student in 96 Experimental Class at Shenzhen Middle School (1996-2001).

Mr. Liu now is one of the Under-Graduate Class-Representatives in CS Department. He is also a member of HKUST International Collegiate Programming Contest Team.

你的程序太长,太花时间来看!

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧