All pastes #189301 Raw Edit

rvsjoen

public cpp v1 · immutable
·published 2006-10-02 23:49 UTC
rendered paste body
int main ( int argc, char *argv[] ){ Matrise A(3,3); KvMatrise B(3); cin >> A; B = A;  ( KvMatrise = Matrise ) <- invoking the assignment operator WHY DOES THIS NOT WORK ?!}class KvMatrise : public Matrise{        public:                KvMatrise(int);                KvMatrise(Matrise);                KvMatrise& operator=(const Matrise&);};class Matrise {        public:                Matrise();                Matrise(int c, int r);                Matrise(const Matrise &src);                ~Matrise();                Matrise& operator=(const Matrise&);};KvMatrise::KvMatrise(int n): Matrise(n,n){}KvMatrise::KvMatrise(Matrise m): Matrise(m){}KvMatrise& KvMatrise::operator=(const Matrise& km){        cout << "Calling assignment operator" << endl;        static_cast<Matrise>(*this) = km;        return *this;}Matrise::Matrise(): cols(1), rows(1) {}Matrise::Matrise(int c, int r) : cols(c), rows(r) {        matrise = new int*[rows];        for(int i=0; i<rows; i++)        {                matrise[i] = new int[cols];                for(int j=0; j<cols; j++)                {                        matrise[i][j] = 0;                }        }}Matrise::Matrise(const Matrise& src){        rows = src.rows;        cols = src.cols;        matrise = new int*[rows];        for(int i=0; i<rows; i++)        {                matrise[i] = new int[cols];                for(int j=0; j<cols; j++)                {                        matrise[i][j] = src.matrise[i][j];                }        }}