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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:43:36+00:00 2026-05-31T07:43:36+00:00

I am writing a simple data to XML serializer for training purposes. The idea

  • 0

I am writing a simple data to XML serializer for training purposes. The idea is to pass values to a serialize function that will do something to bring the given values into a string format. Many types do have built in conversions, but for many I want to have a specialized function doing this. My approach is:

I have a template function with this signature:

template <class T> void serialize(T *value, Serializer *serializer);

and I can specialize the template like this:

template <> void serialize<bool>(bool *value, Serializer *serializer);

Works fine. Now I want to write a serialize function for a vector, as in:

template <class T> void serialize<std::vector<T*> >(std::vector<T*> *value, Serializer *serializer) {
    serializer->begin_section("array");
    for(std::vector<T*>::iterator it = value->begin(); it != value->end(); it++) {
        serializer->add_value(*it);
    }
    serializer->end_section();
}

But when I compile it (g++ 4.6.2), I get error: function template partial specialization ‘serialize<std::vector<T*> >’ is not allowed. Is there a way I can do this?

  • 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-31T07:43:37+00:00Added an answer on May 31, 2026 at 7:43 am

    Your problem is that you wish to provide a template specialization that is a template itself.

    The simplest way to resolve your problem is to not use template specialization at all and instead rely on function overloading.

    template<class T> void serialize(T *value, Serializer *serializer);
    

    can still provide a default implementation, but if a more specialized version like

    void serialize(bool *value, Serializer *serializer);
    

    exists, it will be preferred by the overload resolution.
    This allows you to simply define a function like

    template <typename T> void serialize(::std::vector<T> *value, Serializer *serializer);
    

    that will be called for vectors. (Consider that ::std::vector is more specialized than T, so overload resolution will pick this function where it is possible).

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

Sidebar

Related Questions

So I'm writing a Java application that uses Simple to store data as xml
I'm writing a simple function that split binary/post-data/html from a HTTP response. The HTTP
I'm writing a simple tool in Qt which reads data from two GPX (XML)
I'm writing a simple url-based API that retrieves data and sends it back in
BACKGROUND I'm writing a method that will (eventually) take as input a System.Data.DataTable and
I'm writing a user-defined function to extract values from an XML column in SQL
I'm writing a server with Boost, something pretty simple - accept an XML message,
I'm writing some code that handles logging xml data and I would like to
I am writing a game for Android that requires a ton of simple data
I'm writing a simple data UI using standard .Net databinding to a typed DataSet

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.