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 8914797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:49:03+00:00 2026-06-15T04:49:03+00:00

For the upcoming Coursework in January, I started developing a small DirectX engine. To

  • 0

For the upcoming Coursework in January, I started developing a small DirectX engine. To find out if there is a performance increase I wanted to try to not use any virtuals at all (I know that virtuals aren’t all bad, but I just wanted to see if it is possible without them).

When I started playing around with a simple StateManager, it got hard to avoid virtuals, but this is my current approach:

#include <boost\function.hpp>
#include <boost\bind.hpp>

template <class Derived>
struct TBaseState {
  bool update(float delta) {
    return static_cast<Derived *>(this)->update(delta);
  };
};

struct CTestState : TBaseState<CTestState> {
  bool update(float delta) {
      return true;
  }
};

class StateManager
{
public:
    template <class StateClass> static void setState(StateClass nextState)
    {
        m_funcptrUpdate = boost::bind(&TBaseState<StateClass>::update,     boost::ref(nextState), _1);
    }
    static bool update(float delta) 
    {
        return m_funcptrUpdate(delta);
    }
protected:
private:
    static boost::function<bool (float)> m_funcptrUpdate;
};

Visual Studio 2010’s Intellisense seems to think everything is fine, but when I want to compile the program and test the StateManager with a very basic approach:

CTestState* t = new CTestState(); 
StateManager::setState(*t);
StateManager::update(0.0f);

The following error is thrown during linking phase:

error LNK2001: unresolved external symbol "private: static class boost::function<bool __cdecl(float)> StateManager::m_funcptrUpdate" (?m_funcptrUpdate@StateManager@@0V?$function@$$A6A_NM@Z@boost@@A)

So obviously he can’t find the binded function, but how can I solve this issue? I get similar errors if I use boost::bind directly to some class. Since I am a computer science student I would also be interested in some insight or approaches without boost (e.g. bind1st, …).

EDIT:
I was also thinking about using C++11 Variadic Templates, but one of the coursework requirements is to stick to VS2012.

  • 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-15T04:49:05+00:00Added an answer on June 15, 2026 at 4:49 am

    Static class members need to be given storage. They’re like extern variables. Add a definition to one of your .cpp files, outside of the class definition:

    boost::function<bool (float)> StateManager::m_funcptrUpdate;
    

    Also, in this code:

    template <class StateClass> static void setState(StateClass nextState)
    {
        m_funcptrUpdate = boost::bind(&TBaseState<StateClass>::update,
            boost::ref(nextState), _1);
    }
    

    You’re maintaining storing a reference to the local variable nextState. That reference will be invalid after setState returns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the upcoming WCF Web API , is there any way to control JSON
I am studying for an upcoming assignment and trying to figure out what the
In preparation for the upcoming Google Code Jam, I've started working on some problems.
Is there any update in the upcoming C++0x standard on named parameters in templates
With the upcoming release of Visual Studio 2012, are there project templates for managing
Is there a good existing or upcoming alternative in C# to declaring data structures
For a upcoming project, there are plans to port the existing C++ code that
Is there a new upcoming C Standard that supersedes C99? After all there's an
Anybody has experience with the upcoming IE9 Chakra engine? I am currently considering whether
We are contemplating building an upcoming project in Silverlight. We would be developing this

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.