C++ 静态函数:此处不能指定存储类
我以这种方式在类中将函数定义为静态函数(相关代码片段) 并在.cpp文件中作为C++ 静态函数:此处不能指定存储类,c++,visual-studio-2010,class,static,C++,Visual Studio 2010,Class,Static,我以这种方式在类中将函数定义为静态函数(相关代码片段) 并在.cpp文件中作为 #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
#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
}
#包括“stdafx.h”
#包括“connectivityClass.h”
静态std::string neightratt::intToStr(整数)
{
std::stringstream ss;//创建一个stringstream
ss在.cpp
文件的定义中,删除关键字static
:
// No static here (it is not allowed)
std::string neighborAtt::intToStr(int number)
{
...
}
只要头文件中有static
关键字,编译器就知道它是静态类方法,因此不应该也不能在源文件的定义中指定它
在C++03中,存储类说明符是关键字auto
、register
、static
、extern
和mutable
,它们告诉编译器数据是如何存储的。如果看到一条错误消息引用存储类说明符,可以确定它引用的是这些关键字之一
在C++11中,auto
关键字具有不同的含义(它不再是存储类说明符).您确定可变的?它在BNF中显示为存储类说明符,但它的行为不一样。而thread\u local
在C++11中是存储类说明符。@BenVoigt:是的,C++03§7.7.1明确列出了这5个说明符。
// No static here (it is not allowed)
std::string neighborAtt::intToStr(int number)
{
...
}