E
ejstans
Hello,
I encountered something unfamiliar to me today and I would like some
clarifications. Unfortunately I don't have access to a standard but
even if I did, I'm not even sure if I could understand it well enough
to answer my question...
Here's the deal: without instantiating the class, the code in question
calls both static and non-static member functions like this:
class foo {
public:
static void bar() { std::cout << "bar" << std::endl; }
void bar2() { std::cout << "bar2" << std::endl; }
};
void
func(foo* f)
{
f->bar();
f->bar2();
}
int
main()
{
func(NULL);
return 0;
}
Is this allowed? And if it is, does a situation exist where it would
be an advisable way of doing things?
I encountered something unfamiliar to me today and I would like some
clarifications. Unfortunately I don't have access to a standard but
even if I did, I'm not even sure if I could understand it well enough
to answer my question...
Here's the deal: without instantiating the class, the code in question
calls both static and non-static member functions like this:
class foo {
public:
static void bar() { std::cout << "bar" << std::endl; }
void bar2() { std::cout << "bar2" << std::endl; }
};
void
func(foo* f)
{
f->bar();
f->bar2();
}
int
main()
{
func(NULL);
return 0;
}
Is this allowed? And if it is, does a situation exist where it would
be an advisable way of doing things?