bcb2007的bug

onemonth 2007-07-06 10:16:07
bcb到了2007,还是没有改正bcb6的bug。
定义如下:
template<class T1>
class TMain
{
private:
T1 _t1;
};

template<class T>
class TParam
{
private:
template<class F>
friend TParam<F> & operator + (TParam<F> & p1, int n);
};

template<class F>
TParam<F> & operator + (TParam<F> & p1, int n)
{
}

以下实例化
typedef TParam<int> param_type;
typedef TMain<param_type > main_type;

编译不能通过。
如果把 TMain 的 _t1 声明为 指针,就可以编译通过。
gcc 3.4.2下都可以通过。
...全文
396 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
勉励前行 2007-07-08
  • 打赏
  • 举报
回复
template<class F>
TParam<F> & operator + (TParam<F> & p1, int n){}

寫這樣的模板,不小心用錯了+號,怎麼辦啊。建議這裡不用模板,有多少種類型就寫多少種。
  • 打赏
  • 举报
回复
这样的代码就能够编译过去
template<class T1>
class TMain
{
private:
T1 _t1;
};

template<class T>
class TParam
{
private:
template<class F>
friend TParam<F> & operator + (TParam<F> & p1, int n)
{

}
};
int main(int argc, char* argv[])
{
typedef TParam<int> param_type;
typedef TMain<param_type > main_type;
main_type xxx;
return 0;
}
  • 打赏
  • 举报
回复
template<class F>
TParam<F> & operator + (TParam<F> & p1, int n)
{
}
你这是在写一个新的模板
FFSB 2007-07-06
  • 打赏
  • 举报
回复
hoho
hellolongbin 2007-07-06
  • 打赏
  • 举报
回复
呵呵
___NULL 2007-07-06
  • 打赏
  • 举报
回复
模板是什么东东? 偶经常听说木板
--------------------------------------------
呵呵
cczlp 2007-07-06
  • 打赏
  • 举报
回复
模板是什么东东? 偶经常听说木板
constantine 2007-07-06
  • 打赏
  • 举报
回复
俺不用模板的说
i_love_pc 2007-07-06
  • 打赏
  • 举报
回复
接分!!
  • 打赏
  • 举报
回复
你没用的话,编译通过正常,编译不通过也正常.
这不是BCB的bug 呵呵.
onemonth 2007-07-06
  • 打赏
  • 举报
回复
akirya(坏[其实偶不是什么所谓的坏人])
-------------------------------------
你说的不错,我奇怪的是指针就能行。我没有真正运行过这个代码,只是编译,只是奇怪gcc能通过,而bcb不行。从现象来看,也许是指针没有编译。
根据设计,这个代码应该是
template<class T>
class TParam
{
friend operator + (TParam<T> & p, int n);
};
这样的代码才体现了设计意图。
我啃 2007-07-06
  • 打赏
  • 举报
回复
……大多编译器对模板支持都有问题
theLibra12 2007-07-06
  • 打赏
  • 举报
回复
很少用模板!
  • 打赏
  • 举报
回复
或者这样写
template<class T1>
class TMain
{
private:
T1 _t1;
};

template<class T>
class TParam;
template<class F>
TParam<F> & operator + (TParam<F> & p1, int n);//先声明函数模板

template<class T>
class TParam
{
private:
template<class F>
friend TParam<F> & operator + (TParam<F> & p1, int n);//声明为友元
};

template<class F>
TParam<F> & operator + (TParam<F> & p1, int n)//实现函数模板
{
}


int main(int argc, char* argv[])
{
typedef TParam<int> param_type;
typedef TMain<param_type > main_type;
main_type xxx;
return 0;
}

552

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 茶馆
社区管理员
  • 茶馆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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