Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15254
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: "f() const;", defined inside a struct ( i.e. a "class" ). |
| Date | 2012-04-08 22:22 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jlsvij$v6i$1@speranza.aioe.org> (permalink) |
| References | <d8d21a09-f8b8-4644-8967-8095ee1c6eca@f27g2000yqc.googlegroups.com> <e0dfbedf-9308-48b4-ac89-3ce8d63497a1@h12g2000yqi.googlegroups.com> <Jeff-Relf.Me@2012_Apr.8^0.56^PM> <5402189.2428.1333915876342.JavaMail.geo-discussion-forums@ynbi17> |
danny.gratzer@gmail.com wrote:
> I see, are there any other modifiers that can be placed in that position
> besides const?
Yes, a member function may be declared as const and/or volatile.
Just to provide you with some insight, in the C++ programming language
member functions may be interpreted as being funcions which have an implicit
parameter which takes a pointer to an object of a particular class. So,
conceptually, in the following example both Foo::member_do() and
function_do(Foo *) would be equivalent:
<code>
class Foo
{
public:
void member_do() {};
};
void function_do(Foo *)
{
}
</code>
With this in mind, when you declare a member function as const, volatile or
const volatile, you are declaring how that function accesses the pointer to
an object of that class. So, tweaking the previous example, the following
would also be equivalent:
<code>
class Foo
{
public:
void member_do() const {};
void member_do() volatile {};
void member_do() const volatile {};
};
void function_do(const Foo *)
{
}
void function_do(volatile Foo *)
{
}
void function_do(const volatile Foo *)
{
}
</code>
Hope this helps,
Rui Maciel
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question on Basic Function Syntax Danny Gratzer <danny.gratzer@gmail.com> - 2012-04-08 12:40 -0700
Re: Question on Basic Function Syntax Paul N <gw7rib@aol.com> - 2012-04-08 12:42 -0700
"f() const;", defined inside a struct ( i.e. a "class" ). @Jeff-Relf.Me - 2012-04-08 12:56 -0700
Re: "f() const;", defined inside a struct ( i.e. a "class" ). danny.gratzer@gmail.com - 2012-04-08 13:11 -0700
Re: "f() const;", defined inside a struct ( i.e. a "class" ). Rui Maciel <rui.maciel@gmail.com> - 2012-04-08 22:22 +0100
Re: "f() const;", defined inside a struct ( i.e. a "class" ). danny.gratzer@gmail.com - 2012-04-08 13:04 -0700
Re: "f() const;", defined inside a struct ( i.e. a "class" ). Victor Bazarov <v.bazarov@comcast.invalid> - 2012-04-08 16:46 -0400
Re: "f() const;", defined inside a struct ( i.e. a "class" ). Marc <marc.glisse@gmail.com> - 2012-04-08 21:03 +0000
Re: "f() const;", defined inside a struct ( i.e. a "class" ). "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-04-08 23:35 +0200
Re: "f() const;", defined inside a struct ( i.e. a "class" ). nick_keighley_nospam@hotmail.com - 2012-04-10 04:05 -0700
Re: Question on Basic Function Syntax Juha Nieminen <nospam@thanks.invalid> - 2012-04-09 08:03 +0000
Re: Question on Basic Function Syntax Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-10 14:12 +0000
Re: Question on Basic Function Syntax Juha Nieminen <nospam@thanks.invalid> - 2012-04-10 14:30 +0000
Re: Question on Basic Function Syntax Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-10 21:57 +0000
Re: Question on Basic Function Syntax Bo Persson <bop@gmb.dk> - 2012-04-09 14:22 +0200
csiph-web