0

I made a calculator GUI in Qt and separately I made a function that can tokenize and evaluate calculations in c++, but upon attempting to combine the both with a .h file, i got the error: no matching constructor for intialization of calculation::token whenever I used a struct

Minimal reproducible example:

#include <string>

namespace calculation
{
struct token
{
    std::string type;
    double value = -1;
    std::string value_string;
};

void test(){
    // Works fine in g++, error in Qt
    token test{"test",0,"test"};
    return;
    }
}
int main(){
    calculation::test();
    return 0;
}

Once again, this works in standard g++, but produces the same error in qt

onflante
  • 80
  • 5
  • 1
    What do you mean by 'doesn't work in Qt'? Qt isn't a compiler and it doesn't make code like the one you showed not work. What version of g++ you used to compile the file yourself, and what compiler you're using with Qt? – Kaldrr Jun 23 '22 at 07:06
  • I used the g++ 10.0.3 that came with my Ubuntu version. I'm not sure about the exact version qt/qtcreator uses, but it seems to use the gnu compiler as well https://imgur.com/a/7LliY6u – onflante Jun 23 '22 at 07:25
  • 1
    What C++ standard do you use in QT project? My guess is that for QT you're using C++11 and this makes you hit that issue: https://stackoverflow.com/a/18184210/4885321. I.e. using default initializers in struct's body makes the struct non-aggreate. That applies to C++11 only and has changed in newer language standards. – alagner Jun 23 '22 at 08:19
  • @alagner: this indeed resolves the issue. Thank you! – onflante Jun 23 '22 at 09:11

0 Answers0