Title: Πρόβλημα με c++
Post by: AckermanMik on July 25, 2017, 14:51:54 pm
Έχω το παρακάτω προγραμματακι σε c++. #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; } Σε δυο σημεία εκτυπώνω την τιμή του pointer a και ενώ θα ανεμενα να είναι ο ίδιος, βλέπω πάντα πως διαφέρουν οι δυο κατά 4. Καμιά ιδέα; Παράδοξο: Αν σβησω τον destructor όλα δουλεύουν τέλεια.
Title: Re: Πρόβλημα με c++
Post by: c0ndemn3d on July 25, 2017, 20:29:58 pm
Όταν ρωτάς στο StackOverflow, να ετοιμάζεσαι να φας και ράντομ κράξιμο αδελφέ
Title: Re: Πρόβλημα με c++
Post by: AckermanMik on July 25, 2017, 20:56:05 pm
Όταν ρωτάς στο StackOverflow, να ετοιμάζεσαι να φας και ράντομ κράξιμο αδελφέ
Με έκραξαν αλλα βρήκα απάντηση. Closed
|