 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bob Guest
|
Posted: Sun Jul 30, 2006 9:37 pm Post subject: how to invoke a method in C++? |
|
|
My first language is Java and am now transferring to C++. I have two
questions.
(1) In Java, we have a very good API documentation. However, I could
not find an equivalent for C++. I tried to use the MSDN documentation
accompanying Visual Studio 2005. But I found it is not so good as the
JDK documentation provided by Sun. For example, it is not easy to
distinguish from the documentation if a method in C++ is a static
method (invoked without an object), or the method is a instance method
(must be invoked by an object).
(2) The second question is actually the same as the first one. I don't
know in C++ when to invoke a method by an object (object.method()), and
when to invoke a method without an object (method()). Do you know how
to distinguish them? From the API provided by MSDN or elsewhere?
Thanks.
Bob
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Sun Jul 30, 2006 11:37 pm Post subject: Re: how to invoke a method in C++? |
|
|
* Bob:
| Quote: | My first language is Java and am now transferring to C++. I have two
questions.
(1) In Java, we have a very good API documentation.
|
In C++ we have even better! <g> And truth be told, also worse, because
in contrast to Java C++ is much based on using third-party libraries,
which aren't always perfectly documented. In short, be prepared for a
much more varied experience.
| Quote: | However, I could not find an equivalent for C++.
|
The C++ language and standard library is formally documented by the C++
standard. Which is not free, but the PDF version is US $18 or
thereabouts; you'll want the 2003 revision (technical corrigendum 1).
Also, Josutti's book on the standard library is generally recommended.
| Quote: | I tried to use the MSDN documentation
accompanying Visual Studio 2005.
|
That's also available online. Also perhaps check out the SGI STL online
documentation, and the Dinkumware stdandard library online documentation.
| Quote: | But I found it is not so good as the
JDK documentation provided by Sun. For example, it is not easy to
distinguish from the documentation if a method in C++ is a static
method (invoked without an object), or the method is a instance method
(must be invoked by an object).
|
A static member function is denoted by the word 'static'. In addition,
there are free-standing functions that are not class members.
| Quote: | (2) The second question is actually the same as the first one. I don't
know in C++ when to invoke a method by an object (object.method()), and
when to invoke a method without an object (method()). Do you know how
to distinguish them? From the API provided by MSDN or elsewhere?
|
Short determination algo:
if( f is a class member && f is not 'static' )
{
// An non-static member function, call it on an object.
// Well, except for constructors.
obj.f();
pObj->f();
}
else
{
// A freestanding function, no object.
if( f is a class member )
{
// A static member function, marked as 'static'.
ClassName::f();
namespaceName::ClassName::f();
}
else
{
// A namespace scope function.
f();
namespaceName::f();
}
}
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Aug 01, 2006 12:30 am Post subject: Re: how to invoke a method in C++? |
|
|
Bob wrote:
| Quote: | My first language is Java and am now transferring to C++. I have two
questions.
(1) In Java, we have a very good API documentation. However, I could
not find an equivalent for C++. I tried to use the MSDN documentation
accompanying Visual Studio 2005. But I found it is not so good as the
JDK documentation provided by Sun.
|
Shouldn't you complain to MS about that?
| Quote: | For example, it is not easy to
distinguish from the documentation if a method in C++ is a static
method (invoked without an object), or the method is a instance method
(must be invoked by an object).
|
Not many standard class members are static.
I can recommend http://www.dinkumware.com/manuals/ as a potential
replacement for MSDN Library.
| Quote: | (2) The second question is actually the same as the first one. I don't
know in C++ when to invoke a method by an object (object.method()),
and when to invoke a method without an object (method()). Do you know
how to distinguish them? From the API provided by MSDN or elsewhere?
|
From docs, from compiler manuals, from books, from the Standard, from
online sources...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Wed Aug 02, 2006 12:59 am Post subject: Re: how to invoke a method in C++? |
|
|
In article <NmIzg.29192$so3.22929 (AT) southeast (DOT) rr.com>, Jeffrey Schwab
<jeff (AT) schwabcenter (DOT) com> writes
| Quote: | Really? I always use it to distinguish functions that are members of
classes from functions that are not.
|
You may but it is not idiomatic language in the broader C++ community
where we normally talk of member-functions and (free) function.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' and "You Can Program in C++"
see http://www.spellen.org/youcandoit
For project ideas and contributions:
http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|