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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:48:31+00:00 2026-05-13T05:48:31+00:00

I still can’t get it to work.. After I had to separate implementation from

  • 0

I still can’t get it to work..

After I had to separate implementation from definition of one of my generic classes because of a forward declaration, i now get Linker errors when trying to build.

IShader.h:

template <typename ShadeType> 
class IShader {

public:
template <typename T>
bool getProperty(const std::string& propertyName, ShaderProperty<T>** outProp);
};

so it’s a generic class with a generic member function with a different generic type

implementation looks like this:

#include "MRIShader.h"

template <typename ShadeType> template <typename T>
bool IShader<ShadeType>::getProperty(const std::string& propertyName, ShaderProperty<T>** outProp){
    std::map<std::string, IShaderProperty* >::iterator i = m_shaderProperties.find(propertyName);
    *outProp = NULL;
    if( i != m_shaderProperties.end() ) {
        *outProp = dynamic_cast<ShaderProperty<T>*>( i->second );
        return true;
    }
    return false;
}

but i get Linker errors like this one:

error LNK2001: Nicht aufgelöstes externes Symbol ""public: bool __thiscall IShader<class A_Type>::getProperty<bool>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class ShaderProperty<bool> * *)" (??$getProperty@_N@?$IShader@VA_Type@@@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAPAV?$ShaderProperty@_N@@@Z)".   SceneParser.obj

for bool, but also for many other types.
I already read through this article:
http://www.parashift.com/c++-faq-lite/templates.html

but adding

templace class IShader<bool>;

in the end of IShader.cpp doesn’t solve the problem.
I also tried to add the ‘export’ keyword before the keyword ‘template’ in the implementation, but this just gives me a syntax error.

What’s the proper way to declare and implement my template class, which has templated member methods (with a different template type!) in separate files (.h and .cpp) without getting Linker errors?

thanks!

  • 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-13T05:48:31+00:00Added an answer on May 13, 2026 at 5:48 am

    Your only providing a linkable object for the class in the translation unit, but the member function is templated on another parameter and has also to be explicitly specified.

    I don’t know if there is a more elegant way, but one compilable version would be:

    template bool IShader<bool>::getProperty<bool>
                     (const std::string& propertyName, 
                      ShaderProperty<bool>** outProp);
    

    VC8 and GCC 3.4 both allow to leave out the <bool> after the function name. I’m however not sure about the correct syntax in that case.

    But as long as you’re not having problems with the compilation time in a big project, save yourself the trouble and put the method definitions (marked inline) in a header.
    If you’re just worried about the size of the header file, move the definitions in another header file, e.g. IShaderImpl.h, that you include at the end of IShader.h.

    Quick sample to remove doubts:

    // IShader.h
    template<typename T>
    struct ShaderProperty {};
    
    template <typename T> 
    class IShader {
    public:
        template <typename U>
        void getProperty(ShaderProperty<U>**);
    };
    
    // IShader.cpp
    #include <iostream>
    #include "IShader.h"
    
    template<typename T> template<typename U>
    void IShader<T>::getProperty(ShaderProperty<U>**) 
    { std::cout << "moo" << std::endl; }
    
    template class IShader<bool>;
    template void IShader<bool>::getProperty(ShaderProperty<bool>**);
    
    // main.cpp
    #include "IShader.h"
    int main() {
        IShader<bool> b;
        ShaderProperty<bool>** p;
        b.getProperty(p);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.