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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:38:27+00:00 2026-06-06T22:38:27+00:00

I have been stumped all day on this problem. Basically I want to check

  • 0

I have been stumped all day on this problem. Basically I want to check to confirm the template type inherits from a class that will work for what I’m doing. To do this I used std::enable_if, and I have something that works the way I want it to at compile time, but I keep getting liker undefined reference errors when I try to actually do something with the class.

class TrainingCompare
{
public:
    virtual bool operator() (PUnitType& lhs, PUnitType& rhs)=0;
};

// The following Magic will result in a type error if T does not inherit from TrainingCompare
template<class T, class Enable = void>
class TrainAction;

template <class T>
class TrainAction<T,
    typename std::enable_if< std::is_base_of< TrainingCompare, T >::value>::type>
    : public BasicAction
{
    priority_queue<UnitType, vector<PUnitType>, T> trainQueue;
public:
    TrainAction();
    void addUnitRequest(UnitType uType, int priority = 0);
};

To get the source file to compile was a challenge but what I came up with looked like total crap to have a lot of so I made a macro to shrink the code.

#include "TrainAction.h"

#define Magic(rtype) template <class T>\
    rtype TrainAction<T, typename std::enable_if< std::is_base_of< TrainingCompare, T >::value>::type>

template<class T>
TrainAction<T, typename std::enable_if< std::is_base_of< TrainingCompare, T >::value>::type>::TrainAction()
{
    group = NULL;
}

Magic(void)::addUnitRequest(UnitType uType, int priority = 0)
{
    trainQueue.push(PUnitType(UnitType));
}

I have the feeling that my macro is wrong but my header is right, but that’s just a hunch. Thanks in advance.

1>ExampleAIModule.obj : error LNK2001: unresolved external symbol "public: void __thiscall TrainAction<class TrainComp,void>::addUnitRequest(class BWAPI::UnitType,int)" (?addUnitRequest@?$TrainAction@VTrainComp@@X@@QAEXVUnitType@BWAPI@@H@Z)
1>ExampleAIModule.obj : error LNK2001: unresolved external symbol "public: __thiscall TrainAction<class TrainComp,void>::TrainAction<class TrainComp,void>(void)" (??0?$TrainAction@VTrainComp@@X@@QAE@XZ)
1>C:\bwapi4\broodwarbot\branches\DR_BWAIModule\Release\ExampleAIModule.dll : fatal error LNK1120: 2 unresolved externals
  • 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-06T22:38:30+00:00Added an answer on June 6, 2026 at 10:38 pm

    The problem is that all template code must be in the headers.

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

Sidebar

Related Questions

I have been stumped for 3 hours now on this problem, I need to
This problem has been driving me nuts all day and there has to be
Hey this might be a simple question, but i have been stumped on it
I have been very stumped by this one. I have a fairly large (~1500
I've been banging away at this problem most of the day and I'm just
I have been googling about this issue for hours, and I'm stumped. Im trying
I have been working on an app all day which has been working fine
I have been stumped on this for about an hour. I have the following
Well I have been stumped as to the best way to do this, I
I have to admit I am COMPLETELY stumped on this one. I've been scouring

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.