-2

Here is my code:

// head file
class JsonResponse
{
public:
    template<typename T>
    void add(const string &, const T &);
};

template<typename T>
void JsonResponse::add(const string & name, const T & t)
{
    // do something
}

I compile it and get this error:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Can you help me? thanks a lot.

Yves
  • 11,597
  • 17
  • 83
  • 180

2 Answers2

0

This is not a template error. you are using string, which is not resolved unless there is a using namespace std directive. You should be using std::string instead

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
  • omg.... I was cheated by Visual Studio again..... Sometimes the color hint doesn't work.... thx a lot. – Yves Jun 29 '15 at 10:02
0

Use template like this , it will work

#include <iostream>
#include <string>

using namespace std;

class JsonResponse
{
    public:
       template<typename T>
       void add(const string &, const T &);
};

template<typename T>
void JsonResponse::add(const string & name, const T & t)
{
    std::cout<<name<<std::endl;
    std::cout<<t<<std::endl;
}

int main(void)
{
    JsonResponse jsonDbl;
    jsonDbl.add("nitendra",3);
    return 0;
}
mystic_coder
  • 462
  • 2
  • 10