Is it possible to define function or method outside class declaration? Such as:
class A
{
int foo;
A (): foo (10) {}
}
int A::bar ()
{
return foo;
}
Is it possible to define function or method outside class declaration? Such as:
class A
{
int foo;
A (): foo (10) {}
}
int A::bar ()
{
return foo;
}
It is possible to define but not declare a method outside of the class, similar to how you can prototype functions in C then define them later, ie:
You can define a method outside of your class
But you cannot declare a method outside of your class. The declaration must at least be within the class, even if the definition comes later. This is a common way to split up the declarations in
*.h
files and implementations in*.cpp
files.Yes, but you have to declare it first in the class, then you can define it elsewhere (typically the source file):