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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:10:27+00:00 2026-06-07T09:10:27+00:00

sorry, if this gets a little complicated. I’ve taken the object and removed everything

  • 0

sorry, if this gets a little complicated. I’ve taken the object and removed everything superfluous to narrow down the cause of the error. This is what’s causing my error:

d3d11module.h

#ifndef STUFF_H
#define STUFF_H

#include <map>
#include <string>
#include <memory>

class D3D11
{
public:
    class Shader;
    template<class T>
    class ShaderRegister;

    typedef std::map<std::string, std::shared_ptr<Shader>(*)()> SHADER_CREATE_MAP;

private:
    static SHADER_CREATE_MAP createMap;
};

class D3D11::Shader
{

};

template<class T>
std::shared_ptr<D3D11::Shader> createShader() {return std::shared_ptr<D3D11::Shader>(new T);}

template<class T>
class D3D11::ShaderRegister
{
public:
    ShaderRegister(std::string const & s)
    {
        D3D11::createMap.insert(std::pair<std::string,std::shared_ptr<Shader>(*)()>(s, &createShader<T>));
    }
};

#endif

just a real quick explanation of all this. There is a class called d3d11 that contains a couple of classes. First the shader class which classes are to be able to derive and implement, but is left blank here because it’s contents have nothing to do with the problem. then i have a map of string indices, that correspond to function pointers.

the ShaderRegister object is to be a static private member within the derived shader classes. Then just outside, the constructor is invoked so that a specified index and a pointer to createShader() is stored at that index. By doing this, invoking the index will call this templated function, returning an instance of that derived shader.

I get the linking error though, when trying to derive the shader object and createing an instance of ShaderRegister and trying to call it’s constructor. Take a look:

#ifndef DIFFUSE_SHADER
#define DIFFUSE_SHADER

#include "d3d11module.h"

class DiffuseShader : public D3D11::Shader
{
    static D3D11::ShaderRegister<DiffuseShader> reg;
};

D3D11::ShaderRegister<DiffuseShader> DiffuseShader::reg("DiffuseShader");

#endif 

doing that causes a quite a painful looking link error.

main.obj : error LNK2001: unresolved external symbol "private: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::tr1::shared_ptr<class D3D11::Shader> (__cdecl*)(void),struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::tr1::shared_ptr<class D3D11::Shader> (__cdecl*)(void)> > > D3D11::createMap" (?createMap@D3D11@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@P6A?AV?$shared_ptr@VShader@D3D11@@@tr1@2@XZU?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@P6A?AV?$shared_ptr@VShader@D3D11@@@tr1@2@XZ@std@@@2@@std@@A)

still, what i think it’s trying to say is the static map object in the d3d11 class is undefined when used at some point. But i thought static objects were constructed at the beginning of the program. So what’s going on?

  • 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-07T09:10:31+00:00Added an answer on June 7, 2026 at 9:10 am

    Static members are declared in the class like everything else, but they also must be defined somewhere in one and only one source (.cpp) file. It’s the same as declaring a member function prototype, then defining the body of the function somewhere else.

    SHADER_CREATE_MAP D3D11::createMap;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before this question gets stamped as a duplicate, I am sorry! I've read ALL
Sorry this is not a very well defined question, I am thinking about an
Sorry this is a basic question, but all my research just barely missed answering
Sorry this is probably super basic. But in all my javabean examples, I've not
sorry this is such a simple question but I can't figure it out. How
I'd like to remove the popup message 'Sorry this video cannot be played' from
Sorry for this simple question, but I can't solve it... There is an example:
Sorry if this question seems stupid, but it's stumped me for a couple days,
Sorry if this is a stupid question, but is there an easy way to
Sorry if this is a dupe. There are many similar questions but it seems

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.