Click here to Skip to main content
13,627,700 members

C / C++ / MFC

 
AnswerRe: CInternetSession OpenURL Pin
Randor 15-May-18 9:46
professional Randor 15-May-18 9:46 
QuestionWhy can't variables be declared in a switch statement Pin
tracyhe12313-May-18 20:34
membertracyhe12313-May-18 20:34 
AnswerRe: Why can't variables be declared in a switch statement Pin
Richard MacCutchan13-May-18 20:58
protectorRichard MacCutchan13-May-18 20:58 
Questionwhy passing argument by reference(&ref) in a template function shows error ? but works fine if arguments passed by pointer(*ptr) ? Pin
Tarun Jha13-May-18 1:46
memberTarun Jha13-May-18 1:46 
AnswerRe: why passing argument by reference(&ref) in a template function shows error ? but works fine if arguments passed by pointer(*ptr) ? Pin
CPallini13-May-18 2:56
mvpCPallini13-May-18 2:56 
GeneralRe: why passing argument by reference(&ref) in a template function shows error ? but works fine if arguments passed by pointer(*ptr) ? Pin
Tarun Jha26-May-18 9:50
memberTarun Jha26-May-18 9:50 
GeneralRe: why passing argument by reference(&ref) in a template function shows error ? but works fine if arguments passed by pointer(*ptr) ? Pin
CPallini26-May-18 10:53
mvpCPallini26-May-18 10:53 
Questionproblem encountered by calling constructors explicitly. Pin
Tarun Jha11-May-18 10:20
memberTarun Jha11-May-18 10:20 
here in the below program i have tried to pass the values of 1d matrix to the object of class Vector by using constructor explicit call.

#include <iostream>
using namespace std;

const int size = 3;
class Vector {
    int *v;

public:
    Vector(){
        v = new int[size];
        for(int i=0; i<size; i++)
            v[i] = 0;
    }
    Vector(int *a){
        for(int i=0; i<size; i++){
            v[i] = a[i] ;
        }

        //display();
    }
    int operator * (Vector &y){
        int sum=0;
        for(int i=0; i<size; i++)
            sum += this->v[i] * y.v[i] ;
        return sum;
    }

    void display(){
        for(int i=0; i<size; i++)
            cout << v[i] << " ";
        cout << endl;
    }
};

int main(){
    int x[3] = {1, 2, 3};
    int y[3] = {6, 3, 9};
    Vector v1, v2;

    v1 = y;
    v2 = x;

    cout << "v1 = ";
    v1.display();

    cout << "v2 = ";
    v2.display();

    cout << "v1 x v2 = " << v1 * v2 << endl ;
    return 0;
}


Quote:
cout << "v1 = ";
v1.display();

cout << "v2 = ";
v2.display();

the above portion of code doesn't works as expected it gives,

Output:

Quote:

6 3 9
6 3 9
v1 = 6 3 9
v2 = 6 3 9
v1 x v2 = 126


Expected:
Quote:
Quote:

1 2 3
6 3 9
v1 = 1 2 3
v2 = 6 3 9
v1 x v2 = 39


Thank you
AnswerRe: problem encountered by calling constructors explicitly. Pin
Joe Woodbury11-May-18 11:39
professionalJoe Woodbury11-May-18 11:39 
GeneralRe: problem encountered by calling constructors explicitly. Pin
Tarun Jha11-May-18 11:57
memberTarun Jha11-May-18 11:57 
AnswerRe: problem encountered by calling constructors explicitly. Pin
CPallini12-May-18 4:13
mvpCPallini12-May-18 4:13 
Questionvs2005 Form window Error C2039 Pin
jimNLX11-May-18 6:31
memberjimNLX11-May-18 6:31 
AnswerRe: vs2005 Form window Error C2039 Pin
Victor Nijegorodov11-May-18 7:23
memberVictor Nijegorodov11-May-18 7:23 
GeneralRe: vs2005 Form window Error C2039 Pin
jimNLX11-May-18 7:28
memberjimNLX11-May-18 7:28 
GeneralRe: vs2005 Form window Error C2039 Pin
Victor Nijegorodov11-May-18 8:07
memberVictor Nijegorodov11-May-18 8:07 
QuestionWhy do I need typecast hex? Pin
Vaclav_11-May-18 5:18
memberVaclav_11-May-18 5:18 
AnswerRe: Why do I need typecast hex? Pin
Richard MacCutchan11-May-18 6:25
protectorRichard MacCutchan11-May-18 6:25 
GeneralRe: Why do I need typecast hex? Pin
Vaclav_11-May-18 6:34
memberVaclav_11-May-18 6:34 
Questionconst char [] and char[] difference question Pin
focusdoit10-May-18 14:26
memberfocusdoit10-May-18 14:26 
QuestionRe: const char [] and char[] difference question Pin
David Crow10-May-18 17:22
memberDavid Crow10-May-18 17:22 
AnswerRe: const char [] and char[] difference question Pin
Richard MacCutchan10-May-18 21:25
protectorRichard MacCutchan10-May-18 21:25 
AnswerRe: const char [] and char[] difference question Pin
Victor Nijegorodov10-May-18 23:03
memberVictor Nijegorodov10-May-18 23:03 
GeneralRe: const char [] and char[] difference question Pin
samzcs11-May-18 2:24
membersamzcs11-May-18 2:24 
QuestionPlease advise me on C++ coding structure Pin
Vaclav_9-May-18 4:24
memberVaclav_9-May-18 4:24 
AnswerRe: Please advise me on C++ coding structure Pin
leon de boer9-May-18 4:44
memberleon de boer9-May-18 4:44 

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.


Advertise | Privacy | Cookies | Terms of Service
Web03-2016 | 2.8.180712.1 | Last Updated 17 Jul 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid