banner
cells

cells

为美好的世界献上 code

Q347

Q347#

#include <iostream>

template<typename T>
void foo(T &x) {
    std::cout << std::is_same_v<const int, T>;
}

template<typename T>
void bar(const T &x) {
    std::cout << std::is_same_v<const int, T>;
}

int main() {
    const int i {};
    int j {};

    foo(i);
    foo(j);
    bar(i);
    bar(j);
}

Answer#

click to see answer 1000

Explain#

只有在 foo(i)T 被推到为 const int,在其余 foobar 调用中 T 被推导为 int

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.