C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Defect report: not possible to declare-but-not-define a full specialization of a variable template

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Mon, 13 Jan 2025 20:19:39 +0000
Is there?
It seems to me that were it to be specialized differently in a different translation unit to all of a sudden do more than advertised, wouldn't that be an ODR violation?

-----Original Message-----
There is a simple workaround: a static variable in a class template:

template <typename T>
struct A {
    static int var;
};
// A<int>::var can be referenced without the initializer being defined at this point

template <> int A<int>::var = 7;

Received on 2025-01-13 20:19:44