0

If a class is having constructor which will take parameters as below

class myclass
{
    public:
        myclass(int a, int b);
};

what are the differences between creating objects as below

myclass a(3, 4);
myclass a = myclass(3, 4);

and which one is better?

kadina
  • 5,042
  • 4
  • 42
  • 83
  • @0x499602D2 Before marking a question as duplicate, please check whether the question is really duplicate or not. The question I asked is nothing to do with the question you mentioned. – kadina Jun 25 '15 at 20:11
  • Your first question addressed the differences between the two forms of initialization. That question is already answered in the duplicate. The second question about which is better is opinion based and is off-topic for this site. But instead of closing this question as primarily opinion based I marked it as a duplicate. – David G Jun 25 '15 at 20:39

1 Answers1

3

The first one is better and recommended. The second one creates a temporary then uses copy construction, although most of the time the copy is elided.

vsoftco
  • 55,410
  • 12
  • 139
  • 252