0

I have a class called Serializer with Serialize and Deserialize methods, on simple types like "int, double, bool etc)"

To extend my possibilities of object serializable, I wanted to make Serializer templated. The goal was to make users of my lib able to create their own Serialization/ Deserialization class, and use it like this :

Serializer< MyOwnSerializationClass>::Serialize(var);

Then Serializer would have called MyOwnSerializationClass::serialize

When I try to do it :

template <class CustomSerializer, typename T>
inline web::json::value Serializer<CustomSerializer>::Serialize(T var)
{
    web::json::value value;

    CustomSerializer::template Serialize(var);
}

CustomSerializer::template Serialize(var);

CustomSerializer is red on visual studio, it says "cannot resolve symbol"

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
Morgan
  • 476
  • 9
  • 23
  • I'm slightly confused why someone would use your `Serializer` class when it looks like they have to implement all of the same functionality in the template argument anyway. Why wouldn't they just use that class instead of giving it as a template argument? – chris Mar 16 '17 at 14:32
  • my goal was to provide some serialization (int, bool) or other common types in the application. Users would create their own class for specific types they need. It avoid having all of our dependencies in the same project, and finally in every project which use it – Morgan Mar 16 '17 at 14:41
  • Okay, so the template argument only has to deal with whatever specific types it wants. In that case, unconditionally calling its `Serialize` function no matter what the type is will not work, but that's a separate issue than what was asked. You'd have to determine if it supports the type and fall back to a default implementation if not. – chris Mar 16 '17 at 14:45
  • @chris: are you really sure that this is a duplicate? Other question is how to call a templated method in a templated class, this one seems to be how to extend a class having a method dealing with common types with an additional type... – Serge Ballesta Mar 16 '17 at 14:54
  • @SergeBallesta, The question as I see it is how to solve the compiler error that was given because the wrong syntax is being used to define a function template of a class template. I suspect there's another question waiting to come out about actually properly being able to extend the default functionality, but the syntax needs to be correct to start with that, and those are two separate questions. – chris Mar 16 '17 at 15:09
  • Assuming OP has correctly declared a templated method you are right. And as as he failed to show the declaration of the method and of the CustomSerializer class, we can assume he did... Ok for me. – Serge Ballesta Mar 16 '17 at 15:18
  • you're right, my main question is resolved, I was confused and thought my error came from the fact it was a static method. Now I face a linking problem, but as you say, it's a seperate question. Thank you – Morgan Mar 16 '17 at 15:26

0 Answers0