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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:16:58+00:00 2026-06-05T01:16:58+00:00

I wrote myself a StringHelper in cpp to convert. But it won’t compile if

  • 0

I wrote myself a StringHelper in cpp to convert. But it won’t compile if I put the sourceode in an external cpp-file (included in the Codeblocks-projectfile) or I don’t understand the errors:

HPP:

#ifndef _INPUT_STRINGHELPER_HPP
    #define _INPUT_STRINGHELPER_HPP

    #include <string>
    #include <sstream>
    #include <deque>

    namespace FiveDimension
    {
        void SplitStream(std::stringstream& s, char c, std::deque<std::string>& ret);
        void SplitString(std::string s, char c, std::deque<std::string>& ret);
        template<typename T> T StringToAll(std::string val);
        template<typename T> bool TryStringToAll(std::string val, T &ret);
        template<typename T> std::string AllToString(T val);
    }

#endif

CPP:

#include "StringHelper.hpp"

void FiveDimension::SplitStream(std::stringstream& s, char c, std::deque<std::string>& ret)
{
    std::string line;

    while(std::getline(s, line, c))
        ret.push_back(line);
}
void FiveDimension::SplitString(std::string s, char c, std::deque<std::string>& ret)
{
    std::string line;
    std::stringstream ss(s);

    while(std::getline(ss, line, c))
        ret.push_back(line);
}
template<typename T> T FiveDimension::StringToAll(std::string val)
{
    std::stringstream s(val);
    T ret;
    s >> ret;
    return ret;
}
template<typename T> bool FiveDimension::TryStringToAll(std::string val, T &ret)
{
    std::stringstream s(val);
    return (s >> ret);
}
template<typename T> std::string FiveDimension::AllToString(T val)
{
    std::stringstream s;
    s << val;
    return s.str();
}

I also tried for example:

template<typename T> std::string FiveDimension::AllToString<T>(T val)
{
    std::stringstream s;
    s << val;
    return s.str();
}

but this doesn’t even compile this file and make me feel I don’t know anything about templates so I came here.
I read the answer by Aaron on this topic: "Undefined reference to" template class constructor . After that I understood a lot more. But how can I predefine a function ?

  • 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-05T01:17:00+00:00Added an answer on June 5, 2026 at 1:17 am

    I’ll do a brief of the answer, that is in the topic, you’ve mentioned:
    There are two ways out of this problem:

    1. Use inlines (I know, that you don’t want to, but it’s more general and correct way).
    2. Use definitions of the types you’ll be using in the .cpp file.

    For template classes you should use the following code:

    template class your_class_name < typename_to_use >;
    

    Where typename_to_use is something like int, std::string or else.
    For template functions you should use the following code:

    template return_type your_function_name<typename_to_use>(...parameters);
    

    For template member functions you should use the following code:

    template return_type your_class_name::your_function_name<typename_to_use>(...parameters);
    

    or

    template return_type your_class_name<class_typename_to_use>::your_function_name<function_typename_to_use>(...parameters);
    

    The last case is describing the situation when the template class uses a template function.

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

Sidebar

Related Questions

I'm trying to compile a c++ program that i wrote myself. And I'm having
I wrote myself a compare function for sort(). It worked well when I put
I wrote myself a custom matcher, which itself works fine. But the failure_message_for_should doesn't
I'm trying to add a IsImage property that I wrote myself to the HttpPostedFile
Sure I could write this myself, but before I go reinventing the wheel is
I've been trying myself, and searching online, to write this regular expression but without
Working on an application to parse robots.txt. I wrote myself a method that pulled
I have a big mess of code. Admittedly, I wrote it myself - a
I have this really simple c++ function I wrote myself. It should just strip
I'm currently trying to test a strcat() function that I wrote myself. Instead of

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.