From reading gotw#84 ( http://www.gotw.ca/gotw/084.htm), I'm convinced that
I should try to make functions nonfriend nonmembers when practical, but
then I came across this:
Bruce Eckel says about operator overloads in Thinking In C++ (2nd Ed - http://www.codeguru.com/cpp/tic/tic0129.shtml)
"In general, if it doesn't make any difference, they should be members, to
emphasize the association between the operator and its class."
That seems like a valid point, but probably not as convincing as the ones
Sutter gives. For example, a nonmember nonfriend might be generic enough
to be usable outside of the class; no reason to unnecessarily hide the
logic inside the class.
Does Eckel's argument ever outweigh Sutter's?
-Erik
Jul 19 '05
13 2457
jeffc wrote: "Alf P. Steinbach" <al***@start.no > wrote in message news:3f******** ********@News.C IS.DFN.DE... Does Eckel's argument ever outweigh Sutter's?
I do hope someone authoritative will clarify once and for all whether two, three, four or eight character positions is best for indentation, and also which indentation style to follow. In this regard, should I heed the advice of Bjarne, Herb or Bruce? It's frustrating not to have clear leadership in this important matter.
What on earth are you talking about? Is this some kind of weird troll?
I think he is trying to say that what the OP asked is a similar kind of
political debate, i.e. there's not one answer, and you can simply use your
personal preference.
--
Unforgiven
"Most people make generalisations "
Freek de Jonge
"jeffc" <no****@nowhere .com> wrote in message
news:3f******** @news1.prserv.n et... [...] If the function is virtual, of course it must be a member. If the function is the << or >> operator, make it non-member. If the function needs type conversion on its left most argument, make it non-member (note this is common in operators). Everything else should be a member function.
Ok, so I was thinking of Andrei's "intepretat ion" of Meyers'
rule, which is: "Make everything a free function". ;)
[...] You're using operators as an example. The vast majority of OO functions written are non-operator. The OP didn't ask anything about operators specifically, just functions.
That's ambiguous. He first asked about functions, and then
mentioned what Eckel's had to say about *operators*. So
I assumed he was talking primarily about operators. In
which case, I think Meyers mostly agrees with my summary
(since most binary operators, for instance, benefit from
implicit conversion, and most of the operators that you want
to be members couldn't be free anyway).
Dave
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
"David B. Held" <dh***@codelogi cconsulting.com > wrote in message
news:bn******** **@news.astound .net... You're using operators as an example. The vast majority of OO functions written are non-operator. The OP didn't ask anything about operators specifically, just functions.
That's ambiguous. He first asked about functions, and then mentioned what Eckel's had to say about *operators*. So I assumed he was talking primarily about operators. In which case, I think Meyers mostly agrees with my summary (since most binary operators, for instance, benefit from implicit conversion, and most of the operators that you want to be members couldn't be free anyway).
Yes, I suppose.
"lilburne" <li******@godzi lla.net> wrote in message
news:bn******** ****@ID-203936.news.uni-berlin.de... jeffc wrote: "Alf P. Steinbach" <al***@start.no > wrote in message news:3f******** ********@News.C IS.DFN.DE...
Does Eckel's argument ever outweigh Sutter's?
I do hope someone authoritative will clarify once and for all whether two, three, four or eight character positions is best for indentation,
andalso which indentation style to follow. In this regard, should I heed
theadvice of Bjarne, Herb or Bruce? It's frustrating not to have clear leadership in this important matter.
What on earth are you talking about? Is this some kind of weird troll?
Well I thought it amusing.
Ah, in that case I guess it's pretty funny too. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Wenjie |
last post by:
Hello,
I read someone posted assertions that even the (public) member
function is not static, there are probably only one copy of the
code in the executable. Then except the dependency/independency
on the lifecycle of the object, what is the significant
differences between public member functions and public static
member functions?
|
by: Jian H. Li |
last post by:
Hello,
What's the essential differences between the two ways of "class::member"
& "object.member"(or object_pointer->member)?
class C{
public:
void f() {}
int i;
};
|
by: bluekite2000 |
last post by:
The author's reason is "because its hard to write templates that dont
know whether or not an operation is a member for a given type". What
does he mean by this? An example is appreciated.
|
by: bluekite2000 |
last post by:
I d rather have a Matlab syntax such as:
// create a Matrix of size 3,4 and fills it w/ random values.
Matrix<double> M=rand(3,4)
But since this function changes the state of the object, I ought to
make it a member function.
ie.
|
by: ma740988 |
last post by:
So I'm reading the C++ coding standards(Shutter & Andrei), more
specifically item 56. There's a statement:
"Prefer to provide a nonmember swap function in the same namespace as
your type when objects of your type have a way to exchange their values
more efficiently than via brute-force assignment, such as if they have
their own swap or equivalent function. Additionally, consider
specializing std::swap for your own template types:"
...
| |
by: Terry E Dow |
last post by:
Howdy,
I am having trouble with the objectCategory=group member.Count attribute.
I get one of three counts, a number between 1-999, no member (does not
contain member property), or 0. Using LDIFDE as a comparison I get the same
results. No members means just that, an empty group. Zero means that the
DirectorySearcher.SizeLimit has been exceeded....
|
by: desktop |
last post by:
I have read that the allocator class has the following nonmember functions:
template <class In, class ForFor uninitialized_copy(In,In,For);
template <class For, class T>
void uninitialized_fill(For, For, const T&);
But what does it mean that the two functions are nonmembers? Are they
defined outside the class declaration in the header file?
|
by: WaterWalk |
last post by:
Hello. I thought I understood member function pointers, but in fact I
don't. Consider the following example:
class Base
{
public:
virtual ~Base() {}
};
class Derived : public Base
{
|
by: Immortal Nephi |
last post by:
My project grows large when I put too many member functions into one
class. The header file and source code file will have approximately
50,000 lines when one class contains thousand member functions. Is it
normal how C++ Compiler can compile large class without any problem?
Didn't C++ Compiler have rules to limit the number of member
functions?
One big object has complex operations how member variables and member
functions can be...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |