mardi 22 octobre 2019

Understanding Language syntax of C++ [duplicate]

This question already has an answer here:

Before posting this question I have made many different searches, and I know the answer will already be out there but I believe I am not entering the correct keywords to enable me to find an answer - apologies in advance as I believe this will be a really novice thing.

So in C++ you can do the following on declaration to call a constructor:

class myClass(<this is where the constructor arguments go>);

I am used to the above. When I was searching for an answer to my problem someone posted this:

ifstream file { fileLoc };
string content { istreambuf_iterator<char>(file), istreambuf_iterator<char>() };

The curly braces '{' are something I have not seen before when declaring a variable. Can someone please explain:

  1. What does using the curly braces do? (I don't mean this code specifically - more a general sense of what the curly braces are doing)
  2. Is this something that has always been a part of C++ syntax? Was it introduced in C++11/C++14/C++17? etc.

Thank you for your time answering and my apologies that it is no doubt something so trivial. I just like to understand the languages I develop in as complete as possible.

Aucun commentaire:

Enregistrer un commentaire