我是靠谱客的博主 听话黑夜,这篇文章主要介绍无法引用 函数 “std::basic_ostream<_CharT, _Traits>::basic_ostream(const std::basic_ostream<char, std::char,现在分享给大家,希望可以做个参考。

无法引用 函数 “std::basic_ostream<_CharT, _Traits>::basic_ostream(const std::basic_ostream<char, std::char_traits> &) [其中 _CharT=char, _Traits=std::char_traits]” (已隐式声明) – 它是已删除的函数

在打出以下代码出现了这个错误。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream> using namespace std; class Myint { friend ostream operator<<(ostream & output,Myint m); public: Myint() { num=0; } Myint(int num) { this->num=num; } Myint & operator++(); private: int num; }; Myint & Myint::operator++() { this->num++; return *this; } ostream operator<<(ostream & output,Myint m) { output<<m.num<<endl; return output; } void test1() { Myint m; cout<<++m<<endl; } int main() { test1(); return 0; }

但是在重载输出流符号的全局函数的返回值加上引用就可以了,之前的错误可能是因为在重载输出流函数执行完毕返回的输出流类型被释放发生的错误。在加入引用后就解决掉了

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream> using namespace std; class Myint { friend ostream & operator<<(ostream & output,Myint m); public: Myint() { num=0; } Myint(int num) { this->num=num; } Myint & operator++(); private: int num; }; Myint & Myint::operator++() { this->num++; return *this; } ostream & operator<<(ostream & output,Myint m) { output<<m.num<<endl; return output; } void test1() { Myint m; cout<<++m<<endl; } int main() { test1() return 0; }

最后

以上就是听话黑夜最近收集整理的关于无法引用 函数 “std::basic_ostream<_CharT, _Traits>::basic_ostream(const std::basic_ostream<char, std::char的全部内容,更多相关无法引用内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部