I am trying to call a static method from a.h to b.cpp. from what I have researched, it is as simple as just putting a :: scope resolution but however I tried and it throws me an error "C++ requires a type specifier for all declarations". below is what I have.
a.cpp
float method() {
//some calculations inside
}
a.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.
I quite confused and need guidance.
It's tough to understand what it is you're trying to do. Try something like:
a.h
a.cpp
b.cpp
If you simply have
you are just dumping some instructions in the middle of "nowhere" (well somewhere you could declare a function, define a function or do something evil like define a global, all of which require a type specifier to start with)
If you call your function from another method, say
main
the compiler will think you are calling a method rather than trying to declare something and failing to say what type it is.edit
If you really have a static methid in a class, say
class A
declared in a header calleda.h
you call it this way, using the scope resoution operator as you have said, being careful not to dump random function calls at global scope, but to put them inaside methods.If the question is also how to declare and define the static method this is the way to do it: in a.h:
and then define it in a.cpp