不断"Attempting to reference a deleted function"
Keep getting "Attempting to reference a deleted function"
所以我目前正在尝试制作输出流插入运算符并尝试使其以某种方式显示日期,但我不断收到"尝试引用已删除的函数"错误。我不确定问题可能是什么。有什么帮助吗?
class Date {
private:
static int day;
static int month;
static int year;
public:
static string wordmonth[];
Date(int d, int m, int y) {
this->day = d;
month = m;
year = y;
}
Date(int d) {
this->day = d;
}
Date() {
}
void setDay(int d) {
this->day = d;
}
void setMonth(int m) {
month = m;
}
void setYear(int y) {
year = y;
}
int getDay() {
return day;
}
int getMonth() {
return month;
}
int getYear() {
return year;
}
void print1();
void print2();
void print3();
Date operator ++ () {
day++;
return *this;
}
Date operator ++ (int) {
Date day = *this;
++* this;
return day;
}
Date operator -- () {
day--;
return day;
}
Date operator -- (int) {
--day;
return day;
}
Date operator - (Date v) {
Date temp;
temp.day = day - v.day;
temp.month = month;
temp.year = year;
return temp;
};
这是我正在尝试工作的操作员。
friend ostream operator << (ostream& output, Date& obj) {
output << wordmonth[month - 1] << " " << day << ". " << year;
return output;
}
};
从评论:
Error C2280 'std::basic_ostream<char,std::char_traits<char>>::basic_ostream(const std::basic_ostream<char,std::char_traits<char>> &)': attempting to reference a deleted function
这个错误基本上是说">你不能复制流"(删除的函数是basic_ostream
的复制构造函数,ostream
的基类模板(。
这是因为ostream operator << (ostream& output, Date& obj)
被声明为返回ostream
按值(即副本(。
将其更改为ostream& operator << (ostream& output, Date& obj)
以按引用返回它。
相关文章:
- 不断"Attempting to reference a deleted function"
- C++14 遇到奇怪的"use of deleted function"错误
- 从'deleted function'获取内存错误
- 与映射和unordered_map相关的编译错误:"attempting to reference a deleted function"
- 使用互斥锁和条件变量作为成员时如何修复"use of deleted function"?
- 将 QMutex 添加到类后的"Attempting to reference a deleted function"
- 多级继承错误 C2280:"atttempting to reference a deleted function"
- 构造函数导致"use of deleted function"错误
- 错误:移动承诺时"Attempt to use a deleted function"
- C++:避免"use of deleted function"错误
- C++ 11:线程创建给我一个"Attempt to use a deleted function"错误
- C++:具有 const int 的类的 vector.erase 实例给出"attempting to reference a deleted function"错误 C2280
- "attempting to reference a deleted function"函数参数
- C++错误:"use of deleted function" minGW_32,Qt 5.7.0,Windows 10
- 错误 "Attempting to reference a deleted function" - 传回 unique_ptr 的值时
- SMFL "Cannot be Referenced, it is a deleted function"
- C++ 标准::线程"Attempt to use a deleted function"
- 合并两个unique_ptr向量时'use of deleted function'
- 尝试使用 std::bind 重新分配 std::function 并得到错误"attempting to reference a deleted function"
- 我怎么知道"C2280 - attempting to reference a deleted function"发生在哪里?