I thought that functions always had to have different parameters if they had
the same names. However, this section
( http://www.parashift.com/c++-faq-lit....html#faq-13.8)
of the FAQ creates two operator () methods that take the same parameters.
One is const, the other is not, and the return type is different. However,
I was under the impression that methods with identical names and parameter
signatures would be an error. How does this work? 4 1101
"Aguilar, James" <jf**@cec.NOBOT Swustl.edu> wrote in message
news:cf******** **@newsreader.w ustl.edu... I thought that functions always had to have different parameters if they
had the same names. However, this section (http://www.parashift.com/c++-faq-lit....html#faq-13.8) of the FAQ creates two operator () methods that take the same parameters. One is const, the other is not, and the return type is different.
However, I was under the impression that methods with identical names and parameter signatures would be an error. How does this work?
Because whether a method is const or not is part of its signature.
This is a common and useful technique. In the FAQ is has been used to create
two different operator() methods, only one of which (the non-const version)
allows you to modify the Matrix.
john
Aguilar, James wrote: One is const, the other is not, and the return type is different. However, I was under the impression that methods with identical names and parameter signatures would be an error. How does this work?
The constness of a member function is part of his signature.
You can see it that way: a non static member function has this as a hidden
parameter, if the function is const, is a pointer to a const object, if
not, a pointer to a non-const onbject. Then the parameter list is not
exzactly identical.
--
Salu2
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2n******** ****@uni-berlin.de... [snip]
I'm sorry, maybe I should have formulated my question better. Here's my
real question. How does it know which to pick in these two cases:
m(5,8) = 106.15;
std::cout << m(5,8);
? The function in the first line still doesn't modify the object. The
object ends up modified because of the call, but how does the compiler know
about that when it's deciding what method to call? I thought the const
suffix only applied to things that happen inside the method.
"Aguilar, James" <jf**@cec.NOBOT Swustl.edu> wrote in message
news:cf******** **@newsreader.w ustl.edu... "John Harrison" <jo************ *@hotmail.com> wrote in message news:2n******** ****@uni-berlin.de... [snip] I'm sorry, maybe I should have formulated my question better. Here's my real question. How does it know which to pick in these two cases:
m(5,8) = 106.15; std::cout << m(5,8);
? The function in the first line still doesn't modify the object. The object ends up modified because of the call, but how does the compiler
know about that when it's deciding what method to call? I thought the const suffix only applied to things that happen inside the method.
You are right, whether operator() is being use to read or write an element
of the Matrix is irrelevant.
What determines which version of operator() is called depends on how m is
declared. If m is a const object or a const reference then the const version
gets called, otherwise the non-const version gets called.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Dann |
last post by:
I'm looking at switching from VB6 to .Net but there's one key aspect
that I can't get my head around:
As I understand it, anyone wanting to run an app developed under
VB.Net needs the .Net framework installed. But only WinXP currently
supplies the framework. So how do 98/ME/2K users get a copy? Well of
course business users will very likely have a high speed link for
downloading from MS and those major app developers who distribute...
|
by: Tolga |
last post by:
As far as I know, Perl is known as "there are many ways to do
something" and Python is known as "there is only one way". Could you
please explain this? How is this possible and is it *really* a good
concept?
|
by: Daniel Vukadinovic |
last post by:
Can anyone explain me these things in C++?
1.What is :: used for like in the next case:
if(....
{
...
::one;
|
by: Pieter Coucke |
last post by:
Hi,
For some reason, somewhere in my application 1 hour is added to my dates,
depending in which time zone the application is run...
Because I don't have a clue where this happens, I posted this to the three
relevant newsgroups (vb/ado, sql and xml): my aplogize for this.
I'm doing a Synchronisation between two SQL Servers (2000): All the Data is
read into a DataSet, and exported to an XML-file:
SQL Server -> DataSet (VB.NET 2003) ->...
|
by: MotoK |
last post by:
Hi Experts,
I've just joined this group and want to know something:
Is there something similar to smart pointers in C or something to
prevent memory leakages in C programs.
Regards
MotoK
| |
by: vadam17 |
last post by:
Thanks for your answers.
I already know programming in Java and I am starting studying the
perl. I would like to learn C or C++ but I need someone to tell me
the + and - of each one. I have noticed that every computer exploit
and almost every linux program is builted in C why is that? Because
they just know to program in C or C is better for that kind of
programs and why? Can somebody give an example of big project that
you can achive...
|
by: James |
last post by:
I am new to vb.net (I am an old vb6 programmer). I cannot figure out
an easy way to watch variables. In vb6 all I did was right click and
could chose to stop execution when a variable chances as well as how
extensive a "universe" (context) I want it to watch. In .net I must
work in debug mode but I do not see how to stop execution when a
variable changes nor controlling how brad a context I wish to watch.
Any help would be appreciated
|
by: cj |
last post by:
I'm sure it's simple but it's new to me
I can dim x as new something which defines x as a new instance of
something in one statement. I can also dim x as something then later
make x = new something which does the same thing in a two step process.
Here's what I don't understand and really not sure how to ask but I want
to dim x as something when a program starts and this should be valid for
as long as the program is running. Then when...
|
by: zacariaz |
last post by:
typedef unsigned long long uint64 // just so we dont get confused ;)
ok, the problem is this.
I have 1 + n number of uint64 variables and the 1 should at all times
contain a value equal to the ORing of all the n variables. eg.
@code
uint64 x;
uint64 y;
x = y | y | y ...| y
|
by: jmDesktop |
last post by:
Studying OOP and noticed that Python does not have Interfaces. Is
that correct? Is my schooling for nought on these OOP concepts if I
use Python. Am I losing something if I don't use the "typical" oop
constructs found in other languages (Java, C# come to mind.) I'm
afraid that if I never use them I'll lose them and when I need them
for something beside Python, I'll be lost. Thank you.
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
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...
| |