博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[基础] 模板+友元类外定义
阅读量:4329 次
发布时间:2019-06-06

本文共 821 字,大约阅读时间需要 2 分钟。

下面这种定义方式会报错: Undefined symbols for architecture x86_64

template 
class longint{public: T num; longint (T a = 0) { num = a; } friend ostream& operator<< (ostream& out, const longint
& Lint); ~longint (){ ; }private:};template
ostream& operator<< (ostream &out, const longint
& Lint) { return out<

改法一:将重载运算符的T改成S就行了

//类内声明时template 
friend ostream& operator<< (ostream& out, const longint
& Lint);//类外定义时template
ostream& operator<< (ostream &out, const longint
& Lint) { return out<

改法二:直接在类内定义

friend ostream& operator<< (ostream& out, const longint
& Lint) { return out<

 

转载于:https://www.cnblogs.com/littletail/p/5264122.html

你可能感兴趣的文章
修改tomcatlog输出等级
查看>>
数据结构 堆栈
查看>>
微信公众号开发C#系列-6、消息管理-普通消息接受处理
查看>>
RDIFramework.NET V2.9版本 WinFom部分新增与修正的功能
查看>>
AOP实战
查看>>
最大堆,最小堆及堆排序
查看>>
学习日记
查看>>
EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之:内部搜索功能的实现
查看>>
四则运算--封装5.1
查看>>
Python中dunder名称的来历
查看>>
不知道下一步该怎么走
查看>>
并查集,合根植物
查看>>
C++中String类的字符串分割实现
查看>>
HelloWorld
查看>>
CSS3-animations
查看>>
轮廓系数
查看>>
【Luogu1272】重建道路(动态规划)
查看>>
一次开发逻辑规范的总结
查看>>
Android 中 Movie 类显示GIF图片
查看>>
python学习---朴素贝叶斯算法的简单实现
查看>>