Yuv
Yuv

Reputation: 321

C++ Default and Copy Constructor

Option 1 (BAD):

    Point p1(); 
    Point p2 = p1; //error: conversion from 'Point()' to non-scalar type 'Point' requested

Option 2:

    Point p1 = Point(); 
    Point p2 = p1; //Ok

Option 3:

    Point p1; 
    Point p2 = p1; //Ok

Why is the first one not working and the other two do?

I thought that everything would behave the same, for this example I didn't implement anything in Class Point{} I don't understand why there is a difference between the default constructors

***** EDIT:***** Other constructors would have worked, for example.

    Point p1(4); 
    Point p2 = p1; // will work

So I guess only default Constractor is a problem?

Upvotes: 0

Views: 23

Answers (0)

Related Questions