Reputation:
In C++ how may I write a function that is being called using the class name?
for example if I have a class called test
I want to call a function called calc
like this:
test::calc();
and not via an object of the class.
Upvotes: 2
Views: 1587
Reputation: 11178
class Test {
public:
static void calc() { /* ... */ }
};
int main()
{
Test::calc();
}
Essentially an ordinary function within the namespace of the class.
Upvotes: 1
Reputation: 996
class test{
public:
static void calc(){ /*do stuff */ }
};
See static members
Upvotes: 2