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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:26:16+00:00 2026-06-10T17:26:16+00:00

I got a strange linker error on the following code: The code uses type

  • 0

I got a strange linker error on the following code:

The code uses type traits to provide a partial template specialization for all types A<T> where T is not a subtype of X.

class X{};

#include <type_traits>

//Enabler for all types that are not a subtype of X
#define enabler(T) typename std::enable_if<!std::is_base_of<X, T>::value>::type


//A template (second param is only for enabling partial specializations)
template <typename T, typename = void>
struct A{};

//Partial template specialization for instances
//that do not use a T which is a subclass of X
template <typename T>
struct A<T, enabler(T)>{
    static int foo(); //Declaration only!
};

//Definition of foo() for the partial specialization
template <typename T,enabler(T)>
static int foo(){
    return 4;
}

int bar = A<int>::foo();

int main(){}

Even though this is only one file, linking fails. The problem seems to be the non-inline definition of foo(). Once I inline it, everything works fine. In the real code, I cannot inline it due to circular dependencies.

The error is the following:

/tmp/ccS7UIez.o: In function `__static_initialization_and_destruction_0(int, int)':
X.cpp:(.text+0x29): undefined reference to `A<int, void>::foo()'
collect2: ld returned 1 exit status

So where is the problem?

  • 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-10T17:26:18+00:00Added an answer on June 10, 2026 at 5:26 pm

    The definition of static member function A<T, enabler(T)>::foo has syntax errors, should be :

    template <typename T>
    int A<T, enabler(T)>::foo(){
        return 4;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a strange compilation error when I followed the MSDN document to use
I got a strange error. Source: __init__.py import os import base64 import uuid import
I got this strange line of code today, it tells me 'empty' or 'not
after adding the OCMock framework i got that strange error... :( ld: file not
got strange error Correlation name 'Club' not found but the table Club is in
When I was trying to run the Qt::Phonon::VideoPlayer demo code, I got strange bug.
I got a following error upon linking. A member variable ClassBB::THR can't be accessed
We got strange error last days. ___doPostBack is undefined. We are building quite advanced
I got strange error message when tried to save first_name, last_name to Django's auth_user
I'm a newbie to CakePHP but got strange error. I'm just testing it, how

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.