0

I have the following code:

#include <iostream>
using namespace std;

template <class T> class kickingMyself {
public:
    static int a;
};

template <class T> kickingMyself<T>::a = 0;

int main() {
    kickingMyself<int>::a = 4;
    cout << kickingMyself<int>::a << endl;
    cin.get();
    return 0;
}

on the line:

template <class T> kickingMyself<T>::a = 0;

Im getting the following error:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I don't know why I'm getting this error. please help.

1
  • The error message actually says exactly what the error is and how to fix it. Commented Jul 27, 2013 at 12:20

1 Answer 1

1

You didn't specify the type, which should be int:

template <class T>
int kickingMyself<T>::a = 0;
3
  • Thanks!! Do I have to specity the type for every class, or for template classes only?
    – Billie
    Commented Jul 27, 2013 at 12:18
  • 1
    @user1798362 Yo don’t specify the type for the class (that wouldn’t make sense) – you specify the type for the variable. The syntax for a variable definition always requires the type. Commented Jul 27, 2013 at 12:21
  • 1
    It doesn't make a difference if the class is templated or not. You specify the type when defining methods or declaring static class members.
    – David G
    Commented Jul 27, 2013 at 12:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.