Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8925967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:50:30+00:00 2026-06-15T07:50:30+00:00

I build a template class that is supposed to represent a thread-local pointer. template

  • 0

I build a template class that is supposed to represent a thread-local pointer.

template <class T>
class ThreadLocalPointer {
    public:
        T& operator*() {
            return *_map[std::this_thread::get_id()];
        }

        T* operator->() {
            return _map[std::this_thread::get_id()];
        }
        ThreadLocalPointer<T>& operator=(const T* right) {
            _map[std::this_thread::get_id()] = right;
            return *this;
        }

        T* get() {
            return _map[std::this_thread::get_id()];
        }
    private:
        std::unordered_map<std::thread::id, T*> _map;  
};

Instance of the class:

ThreadLocalPointer<PacketClientHeader*> _incomingBuffer;

And finally, where I want to use my assignment operator

_incomingBuffer = (PacketClientHeader*)malloc(MAX_DATAGRAM_SIZE);

The code won’t compile:

    no operator found which takes a right-hand operand of type 'PacketClientHeader *' (or there is no acceptable conversion)

I’m not sure what I’m doing wrong!

Edit: Included the full template

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:50:31+00:00Added an answer on June 15, 2026 at 7:50 am

    The problem could be that here:

    ThreadLocalPointer<PacketClientHeader*> _incomingBuffer;
    

    the template argument T is PacketClientHeader*, and here:

    ThreadLocalPointer<T>& operator=(const T* right) { .... }
    

    your operator is taking a const T*, which would resolve to const PacketClientHeader**. You then try to assign from a PacketClientHeader* here:

    _incomingBuffer = (PacketClientHeader*)malloc(MAX_DATAGRAM_SIZE);
    

    and no suitable operator is found. Without knowing more details of the class it is difficult to suggest a solution, but it could be as simple as using

        ThreadLocalPointer<PacketClientHeader> _incomingBuffer;
    

    or declaring the assignment operator as

    ThreadLocalPointer& operator=(const T& right) { .... } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to make a class that has a template object member inside
I have a template based class [Allotter.h & Allotter.cpp]: template <typename allotType> class Allotter
I have the following code: template<class T> class RandomTreeNode { public: typedef typename RandomTreeFunction<T>::function_ptr
I'm trying to build a class that stores program settings as a std::map. Since
following the plugins instructions , I build my own generator that creates a template
Lets consider a simple class template< typename T > class Wrapper { public: //
Given a template metaprogram (TMP), do C++ compilers produce build statistics that count the
Say I have a template class that takes msgs from source, does something smart
Say you have a vector class that has a template length and type -
trying to test out move semantics i build a simple class that allocates some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.