Click here to Skip to main content
15,889,724 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: error C2143: syntax error: missing ':' before 'constant' Pin
David Crow27-Mar-18 16:47
David Crow27-Mar-18 16:47 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
ForNow27-Mar-18 16:52
ForNow27-Mar-18 16:52 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
Peter_in_278027-Mar-18 18:13
professionalPeter_in_278027-Mar-18 18:13 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
ForNow28-Mar-18 14:50
ForNow28-Mar-18 14:50 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
Victor Nijegorodov27-Mar-18 21:18
Victor Nijegorodov27-Mar-18 21:18 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
ForNow28-Mar-18 0:31
ForNow28-Mar-18 0:31 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
Richard MacCutchan27-Mar-18 22:08
mveRichard MacCutchan27-Mar-18 22:08 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
Jochen Arndt27-Mar-18 22:41
professionalJochen Arndt27-Mar-18 22:41 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' The Hercules makefile has V1,V2,V3,V4 Pin
ForNow28-Mar-18 15:44
ForNow28-Mar-18 15:44 
Questionproblem understanding a functionality of constructor. Pin
Tarun Jha27-Mar-18 4:39
Tarun Jha27-Mar-18 4:39 
AnswerRe: problem understanding a functionality of constructor. Pin
Jochen Arndt27-Mar-18 4:55
professionalJochen Arndt27-Mar-18 4:55 
AnswerRe: problem understanding a functionality of constructor. Pin
Richard MacCutchan27-Mar-18 5:18
mveRichard MacCutchan27-Mar-18 5:18 
AnswerRe: problem understanding a functionality of constructor. Pin
CPallini27-Mar-18 5:36
mveCPallini27-Mar-18 5:36 
QuestionHackerrank:Down to Zero problem Pin
SrinivasaRamanujan25-Mar-18 10:23
SrinivasaRamanujan25-Mar-18 10:23 
AnswerRe: Hackerrank:Down to Zero problem Pin
David Crow25-Mar-18 15:41
David Crow25-Mar-18 15:41 
QuestionIn type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 5:14
Tarun Jha25-Mar-18 5:14 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
Victor Nijegorodov25-Mar-18 8:07
Victor Nijegorodov25-Mar-18 8:07 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 23:26
Tarun Jha25-Mar-18 23:26 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini25-Mar-18 10:50
mveCPallini25-Mar-18 10:50 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 23:25
Tarun Jha25-Mar-18 23:25 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini26-Mar-18 0:18
mveCPallini26-Mar-18 0:18 
QuestionAdding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 8:19
Tarun Jha24-Mar-18 8:19 
here ih the code below i have tried to add two matrix objects and assign it to the third object but it doesn't give expected result and the rather some garbage value.

include <iostream>
using namespace std;

class matrix{
    int **p;    //pointer to Matrix
    int d1, d2;

public:
    //matrix(){}                  //default constructor
    matrix(int x=20, int y=20);       //parameterised

    void get_element();
    void put_element();
    int checkAdd(matrix &);                                     //to check the feasibility of the operation

    //Rule of three
    matrix operator + (matrix &);
    void operator = (matrix );

    ~matrix(){
        for (int i = 0; i < d1; i++)
            delete p[i];
        delete p;
    }
};

matrix temp;                    //global matrix temp

//=============================================

void matrix::operator = (matrix obj){

    this->d1 = obj.d1;
    this->d2 = obj.d2;
    for(int i=0; i<d1; i++)
        for(int j=0; j<d2; j++)
            this->p[i][j] = obj.p[i][j];

    //put_element();
    //return(*this);
}

matrix matrix::operator+(matrix &obj){
    if(checkAdd(obj)==0)
    {
        //matrix temp;
        for(int i=0; i<obj.d1; i++)
            for(int j=0; j<obj.d2; j++)
                temp.p[i][j] = this->p[i][j] + obj.p[i][j];


        //temp.put_element();
        return(temp) ;
    }

    cout<<"coloumn and rows of both matrix are not equal !"<<endl;
    return (*this);
}

matrix ::matrix(int x, int y)
{
    d1 = x;
    d2 = y;
    p = new int *[d1];                  //creates an array of pointers

    for(int i=0; i<d1; i++)
        p[i] = new int [d2];            //creates row for each row
}

int matrix::checkAdd(matrix &obj){
    if((this->d1 == obj.d1) && (this->d2 == obj.d2))
        return 0;
    else return 1;
}

void matrix::get_element(){
    for(int i=0; i<d1; i++)
        for(int j=0; j<d2; j++){
            cout<<"m["<<i<<"]["<<j<<"] = ";
            cin>>p[i][j];
        }
    //cout<<"Following is your Matrix : \n\n";
    //put_element();
}

void matrix::put_element(){
    cout<<"\n\n";
    for(int i=0; i<d1; i++){
        for(int j=0; j<d2; j++){
            cout<<p[i][j]<<"\t";
        }
        cout<<endl;
    }

}

//=============================================

int main(){
    matrix A(3, 2), B(3, 2), C;                     //matrix objects a constucted

    cout<<"Enter matrix elements row by row \n\n";
    A.get_element();
    A.put_element();

    B.get_element();
    B.put_element();

    C = A + B;
    cout<<"\n\n";
    C.put_element();

    return 0;
}


thank you
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Victor Nijegorodov24-Mar-18 8:35
Victor Nijegorodov24-Mar-18 8:35 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 10:06
Tarun Jha24-Mar-18 10:06 
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan24-Mar-18 21:13
mveRichard MacCutchan24-Mar-18 21:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.