I have a header file helper.h
class helper
{
public:
static int someVal();
};
int helper::someVal()
{
return 999;
}
In my c class I call the someVal method as follows
#include "helper.h"
.
.
int answer = helper::someVal();
Is there way to have a call like this instead?
int answer = someVal();
Solution from below is
helper.h —
static int someVal();
int someVal()
{
return 999;
}
Not exactly, but you can make
helpera namespace instead of a class:You can define the function just as you did in the question. In practice is’s often better to not use
using namespacefor your own functions because that makes it easier to understand which function is called.