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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:17:17+00:00 2026-05-15T12:17:17+00:00

Dear all, I’ve been stuck with this problem now for a few days and

  • 0

Dear all, I’ve been stuck with this problem now for a few days and my searches were not successful.

What I am trying to do:
I want a template reader class (VariableReader) to handle different types of variables (usually unsigned int and pointers to vector).

I started with

#ifndef READER_H_
#define READER_H_
#include <string>

namespace BAT {
template <typename variableType = unsigned int>
class VariableReader {
public:
 VariableReader<variableType>();
 VariableReader<variableType>(std::string varName);
 virtual ~VariableReader<variableType>();
 std::string getVariableName();
 void setVariableName(std::string varName);
 bool isValidVariableName(std::string varName);
 variableType getVariable();
private:
 std::string variableName;
 variableType variable;

};

}

#endif

and

#include "../../interface/Readers/VariableReader.h"

namespace BAT {

template<typename variableType>
VariableReader<variableType>::VariableReader() :
 variableName("") {
 // TODO Auto-generated constructor stub
}

template <typename variableType>
VariableReader<variableType>::VariableReader(std::string varName) :
 variableName(varName) {

}

template <typename variableType>
std::string VariableReader<variableType>::getVariableName() {
 return variableName;
}

template <typename variableType>
void VariableReader<variableType>::setVariableName(std::string varName) {
 if (VariableReader::isValidVariableName(varName)) {
  variableName = varName;
 }
}

template <typename variableType>
bool VariableReader<variableType>::isValidVariableName(std::string varName) {
 return varName != "";
}

template <typename variableType>
VariableReader<variableType>::~VariableReader() {
 // TODO Auto-generated destructor stub
}

}

However, although it seems to compile I can’t use it within other projects.
EDIT: forgot to post test-code:

#include "cute.h"
#include "ide_listener.h"
#include "cute_runner.h"

#include "Readers/VariableReader.h"
using namespace BAT;

static VariableReader<int> *reader;

void setUp(){
reader = new VariableReader<int>::VariableReader();//this is problem-line
}

void thisIsATest() {
    ASSERTM("start writing tests", false);  
}

void runSuite(){
    cute::suite s;
    //TODO add your test here
    s.push_back(CUTE(thisIsATest));
    cute::ide_listener lis;
    cute::makeRunner(lis)(s, "The Suite");
}

int main(){
    runSuite();
}

I get following error message:

Building target: BAT_Tests
Invoking: GCC C++ Linker
g++ -L"/workspace/BAT/Debug Gcov" -fprofile-arcs -ftest-coverage -std=c99 -o"BAT_Tests"  ./src/Test.o   -lBAT
./src/Test.o: In function `setUp()':
/workspace/BAT_Tests/Debug Gcov/../src/Test.cpp:13: undefined reference to `BAT::VariableReader<int>::VariableReader()'
collect2: ld returned 1 exit status
make: *** [BAT_Tests] Error 1

As I understand it the linker tries to find the constructor for VariableReader, which is not explicitly defined since I want to have a general constructor only.

Please help me to understand what I am missing.

  • 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-15T12:17:18+00:00Added an answer on May 15, 2026 at 12:17 pm

    The C++ FAQ Lite section on How can I avoid linker errors with my template functions? shows two solutions:

    1. Move the template class’s methods into the .h file (or a file included by the .h file).
    2. Instantiate the template in the .cpp file using template VariableReader<unsigned int>;.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear all,Now i have this question in my java program,I think it should be
Dear all, I have a question about Facebook Page: ( NOT user profile page,
Dear all, I now have a preliminary macro (defmacro key-if(test &key then else) `(cond
Dear all,I am now using a webtool http://fiddesktop.cs.northwestern.edu/mmp/scrape?url= to parse a webpage. For example,we
Dear all, I am writing a python program that is retrieving edifact log messages
Dear all, I save formatted text (bold, changed in font, style...etc) in an nvarchar(max)
Dear all: In advance, thank you for your time. Lately, I have decided to
Dear All, please help me since I'm newbie in SQL Server. I have a
Dear all, I have a select query that currently produces the following results: DoctorName
dear all..i've a textfield, it using barcode scanner for input data..after scan it shows

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.