C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Suggestion: non-static member variables for static-duration-only classes

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 03 Oct 2025 18:15:18 -0700
On Friday, 3 October 2025 10:25:57 Pacific Daylight Time Walt Karas wrote:
> You can already do this by having a static thread_local member or non-member
> that is your data. It's a bit more typing, but I don't see this as a
> frequent enough need to require direct language support.
>
> Response: I don't understand what you mean by "that is your data".


struct MyClassData;
class MyClass
{
    // methods go here
private:
    static thread_local MyClassData d;
};

Then just have your functions use d.something;

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center Group

Received on 2025-10-04 01:15:43