【发布时间】:2013-10-18 11:44:58
【问题描述】:
我正在尝试将 静态方法 从 a.h 调用到 b.cpp。根据我的研究,它就像放置 :: 范围解析一样简单,但是我尝试过,它给我一个错误“C++ 需要所有声明的类型说明符”。以下是我所拥有的。
a.cpp
float method() {
//some calculations inside
}
啊.h
static float method();
b.cpp
a::method(); <- error! "C++ requires a type specifier for all declarations".
but if I type without the ::
a method(); <- doesn't throw any errors.
我很困惑,需要指导。
【问题讨论】:
-
hmm,
method在我看来不像是一个实际的方法,只是一个普通的函数。 -
删除
a::。只需method();,它更干净。 -
您是否显示了所有的相关代码?静态方法是
class的一部分。如果method不在一个类中,您不希望static用于该声明。 -
in a.h put
static float a::method(); -
您的最后一行
a method();不会抛出任何错误,因为这被解释为函数声明。
标签: c++ visual-c++ c++11 c++-cli c++builder