Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example to call a static function #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions static_interface/a.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
#ifndef A_H
#define A_H

//interface
#include "a_interface.h"
#include "iostream"

//implementation
namespace details
{

Expand All @@ -34,10 +37,12 @@ class A
{
public:
void NOINLINE foo() { g_count += 1; }
static void func0() {std::cout << "calling static f0()" << std::endl;}
};

}

//instanciation
using A = type<interface::A, details::A>;

#endif
2 changes: 2 additions & 0 deletions static_interface/a_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct A
{
constexpr void foo()
{ T::details(this)->foo(); }
constexpr static void func0()
{ T::details_type::func0(); }
};

}
Expand Down
2 changes: 2 additions & 0 deletions static_interface/b.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class B
public:
void bar()
{ m_a.foo(); }
static void func()
{ interface::A<T>::func0();}

private:
interface::A<T> m_a;
Expand Down
2 changes: 2 additions & 0 deletions static_interface/b_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct B
{
constexpr void bar()
{ T::details(this)->bar(); }
constexpr static void func()
{ T::details_type::func(); }
};

}
Expand Down
2 changes: 1 addition & 1 deletion static_interface/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ int main()
{
B<A> b;
b.bar();

B<A>::func();
return 0;
}