Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shading triangles with clang++-8 #29

Open
theIDinside opened this issue Jan 17, 2019 · 1 comment
Open

Shading triangles with clang++-8 #29

theIDinside opened this issue Jan 17, 2019 · 1 comment

Comments

@theIDinside
Copy link

So I am following your course here, and I struggled a bit with the shading lecture. This might be a compiler issue, meaning, the compiler stops me from doing things that I do not want.

My geometry.h basically looks the same as here, and multiplying a vector with a scalar value looks like this:

template <typename T>
struct Vector2D {
...
    inline Vector2D operator*(float scalar) const {
        return Vector2D{x*scalar, y*scalar};
    }
...

However I found that, since I am following the GSL (core guidelines for c++), and using initializer list constructors ( using the {}, instead of () ), the compiler will either complain, or result in faulty code. This might be due to clang in this case, but I suspect MSVC++ and g++ will result in the same compiler error:

error: type 'float' cannot be narrowed to 'int' in initializer list [-Wc++11-narrowing]

So, changing that to:

    inline Vector2D operator*(float scalar) const {
        return Vector2D{static_cast<T>(x*scalar), static_cast<T>(y*scalar)};
    }

Fixes the issue. These are not issues related to the course in itself, but perhaps might be worth noting. If it's irrelevant, just close and remove this issue. Thanks again for awesome content.

@ssloy
Copy link
Owner

ssloy commented Jan 27, 2019

Thank you for your point! In fact, the geometry.h MUST be rewritten completely with modern C++. It was made with c++98 and this is quite ridiculous these days. If you can offer a better implementation, do not hesitate to do a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants