Static function: storage class cannot be specified here

I defined the function as static in my class this way (snippet of the corresponding code)

#ifndef connectivityClass_H #define connectivityClass_H class neighborAtt { public: neighborAtt(); //default constructor neighborAtt(int, int, int); ~neighborAtt(); //destructor static std::string intToStr(int number); private: int neighborID; int attribute1; int attribute2; #endif 

and in the .cpp file as

 #include "stdafx.h" #include "connectivityClass.h" static std::string neighborAtt::intToStr(int number) { std::stringstream ss; //create a stringstream ss << number; //add number to the stream return ss.str(); //return a string with the contents of the stream } 

and I get an error (VS C ++ 2010) in a .cpp file that says: "The storage class cannot be specified here, and I cannot understand what I'm doing wrong.

ps I already read this one that looks like a duplicate, but I don’t know how it does it - that I am right and the compiler is elegant. Any help is appreciated, I cannot find any information about this!

+8
c ++ static class visual-studio-2010
source share
1 answer

In the definition in the .cpp file, remove the static :

 // No static here (it is not allowed) std::string neighborAtt::intToStr(int number) { ... } 

As long as you have the static in the header file, the compiler knows it as a method of a static class, so you should not specify it in the definition in the source file and you cannot specify it.

In C ++ 03, storage class specifiers are the auto , register , static , extern and mutable keywords, which tell the compiler how the data is stored. If you see an error message referencing storage class specifiers, you can be sure to refer to one of these keywords.

In C ++ 11, the auto keyword has a different meaning (it is no longer a storage class specifier).

+19
source share

All Articles