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

  • SEARCH
  • Home
  • 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 6544151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:25:54+00:00 2026-05-25T11:25:54+00:00

I have been relying on the misconception that static variables defined in member functions

  • 0

I have been relying on the misconception that static variables defined in member functions were limited to the specific class instance.

To illustrate my misconception:

#include <iostream>
#include <string>

struct Simple {
    template<typename T>
    T & Test(const T & Value) {
        static T Storage = Value;
        return Storage;
    }
};

int main() {
    Simple A;
    Simple B;

    std::string Foo = A.Test(std::string("Foo"));
    std::string Bar = B.Test(std::string("Bar"));

    std::cout << Foo << ' ' << Bar << std::endl;
}

The behavior I expected would have resulted in the output of

Foo Bar

Is there a simple alternative that would result in the behavior I expected?

Edit

A cutdown version of the class that has the issue:

class SignalManager {
    private:
        template<typename T> struct FunctionPointer { typedef boost::function1<void, const T &> type; };
        template<typename T> struct Array { typedef std::vector<typename FunctionPointer<T>::type> type; };

        template<typename T>
        typename Array<T>::type & GetArray() {
            static typename Array<T>::type Array;
            return Array;
        }

    public:
        template<typename T, typename M>
        void Broadcast(const M & Value) {
            typename Array<T>::type::iterator Iterator;
            for(Iterator = GetArray<T>().begin(); Iterator != GetArray<T>().end(); ++Iterator) {
                (*Iterator)(Value);
            }
        }

        template<typename T, typename F>
        void Connect(const F & Function) {
            GetArray<T>().push_back(Function);
        }
};
  • 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-05-25T11:25:54+00:00Added an answer on May 25, 2026 at 11:25 am

    If I understand your confusion, the alternative is member variables…

    template<typename T>
    struct Simple {
        T storage;
    
        T & Test(const T & Value) {
            storage = Value;
            return Storage;
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been heavily relying on CSS for a website that I am working
Have been trying to encrypt an xml file to a string so that I
I have some working cURL scripts but have been relying on the remote server
I have been developing a WCF project that will expose web services (HTTP-based) that
I have a WCF service-client pair. We have been relying on calling Open() on
Have been working on this question for a couple hours and have come close
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Have been reading about async and tasks and been attempting to convert the CopyFileEx
Have been searching how to convert a dictionary to a string. But the results
Have have been trying to make a validator for my xml files. I have

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.