0

I was reading Peter Shirley's Ray Tracing in One Weekend when I found this in one of his code's classes: vec3() : e{0,0,0} {}

I've searched for a while and I think this is Singleton pattern, but I may be wrong. Can anyone tell me what is this sintax? It would also be helpful if you could tell why is the last {} necessary.

Here's a bigger snippet of the code:

#define VEC3_H

#include <cmath>
#include <iostream>

using std::sqrt;

class vec3 {
    public:
        vec3() : e{0,0,0} {}
        vec3(double e0, double e1, double e2) : e{e0, e1, e2} {}

The full header file is too big to put here, but you can find it on chapter 3.1 of the book

Spagetti
  • 1
  • 1
  • Are you asking about [member initializer list](https://stackoverflow.com/questions/7665021/c-member-initialization-list) `: e{...}`? The last `{}` is the (empty) body of the constructor. – Ted Lyngmo Aug 30 '21 at 10:47
  • [member initializer list](https://en.cppreference.com/w/cpp/language/constructor) – brc-dd Aug 30 '21 at 10:48
  • That and the use of ```:``` between ```vec3()``` and ```e{...}{}``` I've read the link and this seems to be explained as well, thanks for the quick respose – Spagetti Aug 30 '21 at 10:49

0 Answers0