Home Qt Creator: different behavior of class template in Debug and Release modes
Reply: 1

Qt Creator: different behavior of class template in Debug and Release modes

Александр Щетнев
Александр Щетнев Published in 2017-12-07 09:38:10Z

I'm trying to specialize template member function. The problem is that in Debug mode calls specialization of method, but in Release calls non-specialized function.

For example, I have class template and specialized method

template <typename T>
class SimpleClass
    void doSomething(const T& arg)
        std::cout << "doSomething(const T& arg)" << std::endl;
template <>
void SimpleClass<double>::doSomething(const double& arg)
    std::cout << "doSomething(const double& arg)" << std::endl;

int main(int argc, char **argv)
    SimpleClass<double> obj;
    return 0;

I'm expecting, that output will "doSomething(const double& arg)".

So in Debug mode I got it, but in Release I got this: "doSomething(const T& arg)"

My question is why that code behave this way and how can I fix it? Just in case, my .pro file

CONFIG += console c++11
CONFIG -= app_bundle
SOURCES += main.cpp \

edit: I'm using Qt 5.9.1

edit: forgot #include <iostream> before using cout

Murphy Reply to 2017-12-07 10:49:53Z

As you're calling doSomething() with an integer as parameter, I guess the compiler is just trying to find an arbitrary match here. I can't say why debug and release builds behave differently, but I would expect it to work as expected when explicitely using a float value in the call:

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.317371 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO