#include <iostream>
using namespace std;
class station{
int n;
float *p;
public:
station(){};
station(const station &ob){cout<<"Copy";}
station operator=(station* a){cout<<"Nai";}
~station(){cout<<"Destructor";}
static float counter;
friend istream &operator>(istream &stream, station &d);
int &getN(){return n;};
float *&getP(){return p;};
void* operator new[](size_t size);
void* operator new(size_t size){station *a;a=::new station;return a;};
};
void* station::operator new[](size_t size){
station* a;
a=(::new station[size]);
int b;
b=(size)/(sizeof(station));
for(int i=0;i<b;i++){
cin>a[i];
}
cout<<a;
return a;
}
float station::counter;
istream &operator>(istream &stream, station &d){
cout<<"Dwse arithmo deigmatwn";
int num;
stream>>num;
d.getP()=new float[num];
d.getN()=num;
for(int i=0;i<num;i++){
stream>>d.getP()[i];
}
return stream;
}
int main(){
station* a;
a=new station[2];
cout<<a;
return 0;
}
大家好, 這是我的第一篇文章,所以請原諒我的任何錯誤。超負荷新退貨錯地址
我創建了一個新的類,帶有一個新的運算符和一個提取器的重載。我的問題是,由new返回的地址與在重載操作符內部的地址不同,因爲您可以在說明cout<<a
的行中看到該地址。但是,當我刪除析構函數時,一切正常。有任何想法嗎?
爲什麼你重載輸入流的大於比較運算符? –
我只是在重載操作符。 –
那麼,你在鍛鍊如何做錯事? –