help with constructor function

Jul 4, 2020 at 4:23pm
Hello,

I am using a library in which the following constructor is described:

1
2
3
4
5
6
7
8
9
10
11
12
static_assert(std::is_same<T, bool>()
                || std::is_same<T, int>()
                || std::is_same<T, long>()
                || std::is_same<T, long long>()
                || std::is_same<T, float>()
                || std::is_same<T, double>()
                || std::is_same<T, long double>(),
                "Invalid scalar type for Quaternion");


  Quaternion(T a = 0, T b = 0, T c = 0, T d = 0)
  : _a(a), _b(b), _c(c), _d(d) { }


And now I am trying to create the Quaternion:

auto q=Quaternion(1,0,0,0)

Yet is not allowed, and I am getting the message from my IDE that "Ambiguous deduction for template arguments of 'Quaternion'"

Could someone please explain how to use such constructor?
Jul 4, 2020 at 4:36pm
This was unexpected, it seems that actually this is working...I simply did not run the code when I saw that IDE warning.. So once again, how exactly I should write the statement not to get that warning? As it seems for me that I am showing all the members
Jul 4, 2020 at 4:57pm
Can't say without seeing the declaration of the class template and any deduction guides.

You can probably just write
auto q = Quaternion<double>(1, 0, 0, 0);
Last edited on Jul 4, 2020 at 4:58pm
Jul 4, 2020 at 5:34pm
Thank you very much, you were totally right! Thanks again!!!
Jul 5, 2020 at 2:43pm
Since you're passing integers, I assume that's what you want, in which case it should probably be:
auto q = Quaternion<int>(1,0,0,0);
Jul 5, 2020 at 3:25pm
Topic archived. No new replies allowed.