Pointer syntax: Difference between revisions

From vegard.wiki
Jump to navigation Jump to search
Content added Content deleted
(add category)
 
(2 intermediate revisions by the same user not shown)
Line 6: Line 6:


<source lang="C++">
<source lang="C++">
return_type (*name)(args...)
return_type (*function_name)(args...)
</source>
</source>


Line 14: Line 14:


<source lang="C++">
<source lang="C++">
member_type type::*member
member_type type::*member_name
</source>
</source>


Line 21: Line 21:
<source lang="C++">
<source lang="C++">
type obj;
type obj;
obj.*member
obj.*member_name
</source>
</source>


<source lang="C++">
<source lang="C++">
type *obj;
type *obj;
obj->*member
obj->*member_name
</source>
</source>


Line 34: Line 34:


<source lang="C++">
<source lang="C++">
return_type (type::*member)(args...))
return_type (type::*member_name)(args...)
</source>
</source>


Line 41: Line 41:
<source lang="C++">
<source lang="C++">
type obj;
type obj;
(obj.*member)(args...)
(obj.*member_name)(args...)
</source>
</source>


<source lang="C++">
<source lang="C++">
type *obj;
type *obj;
(obj->*member)(args...)
(obj->*member_name)(args...)
</source>
</source>


Line 52: Line 52:
[[Category:C++]]
[[Category:C++]]
[[Category:Programming]]
[[Category:Programming]]
[[Category:Cheat sheets]]

Latest revision as of 13:50, 18 April 2020

C/C++

Pointer to function

Declaration:

return_type (*function_name)(args...)

Pointer to member

Declaration:

member_type type::*member_name

Dereference:

type obj;
obj.*member_name
type *obj;
obj->*member_name

Pointer to member function

Declaration:

return_type (type::*member_name)(args...)

Dereference:

type obj;
(obj.*member_name)(args...)
type *obj;
(obj->*member_name)(args...)