Why doesn't line# 21 create an object of type `C' class? I think the
default construction function invocation `C()' creates a temporary
nameless object, and `o1' will be built with the copy construction
function of the same class from this temporary object. With g++ (GCC)
3.4.2 (mingw-special), line 21 doesn't create `o1' as type of `C'
class. No default and copy constructions are called for this line. I
don't understand this.
For line 22, only C::C(int) is called, no copy construction is called.
Could you please explain this also?
#include <iostream>
class C
{
public:
C(){
std::cout << "C()" << std::endl;
}
C(int ){
std::cout << "C(int)" << std::endl;
}
C(const C &){
std::cout << "C(const C &)" << std::endl;
}
};
int main()
{
C o1(C()); /*line 21*/
C o2(C(0)); /*line 22*/
C o3(o2);
} 6 1412
lovecreatesbea. ..@gmail.com wrote:
Why doesn't line# 21 create an object of type `C' class?
Yes.
I think the
default construction function invocation `C()' creates a temporary
nameless object, and `o1' will be built with the copy construction
function of the same class from this temporary object.
No.
With g++ (GCC)
3.4.2 (mingw-special), line 21 doesn't create `o1' as type of `C'
class. No default and copy constructions are called for this line. I
don't understand this.
Simple, somewhere in the ISO C++ standard they say if some declaration ca be
interpreted as a function declaration then it is a function declaration.
This combined with the (not very well known) fact that functions, besides
declaring them as you usually do: int func(float obj); you can also do it
with the following syntax (they are equivalent) int func(float(obj) );
Because of this and the rule above the explanation is simple. In order to
work arround it just wrap with another set of paranthesis the object
constructor parameter like: C o1((C()));
--
Dizzy http://dizzy.roedu.net
lovecreatesbea. ..@gmail.com wrote:
Why doesn't line# 21 create an object of type `C' class? I think the
default construction function invocation `C()' creates a temporary
nameless object, and `o1' will be built with the copy construction
function of the same class from this temporary object. With g++ (GCC)
3.4.2 (mingw-special), line 21 doesn't create `o1' as type of `C'
class. No default and copy constructions are called for this line. I
don't understand this.
See <http://www.parashift.c om/c++-faq-lite/ctors.html#faq-10.19>.
For line 22, only C::C(int) is called, no copy construction is called.
Could you please explain this also?
The compiler is free to optimize that away in an initialization.
#include <iostream>
class C
{
public:
C(){
std::cout << "C()" << std::endl;
}
C(int ){
std::cout << "C(int)" << std::endl;
}
C(const C &){
std::cout << "C(const C &)" << std::endl;
}
};
int main()
{
C o1(C()); /*line 21*/
C o2(C(0)); /*line 22*/
C o3(o2);
}
Cheers! --M
Dizzy wrote:
lovecreatesbea. ..@gmail.com wrote:
>Why doesn't line# 21 create an object of type `C' class?
Yes.
Love your answer. :-)
lovecreatesbea. ..@gmail.com wrote:
Why doesn't line# 21 create an object of type `C' class? I think the
default construction function invocation `C()' creates a temporary
nameless object, and `o1' will be built with the copy construction
function of the same class from this temporary object. With g++ (GCC)
3.4.2 (mingw-special), line 21 doesn't create `o1' as type of `C'
class. No default and copy constructions are called for this line. I
don't understand this.
info gcc,Invoking GCC, C++ Dialect Options
`-fno-elide-constructors'
The C++ standard allows an implementation to omit creating a
temporary which is only used to initialize another object of the
same type. Specifying this option disables that optimization, and
forces G++ to call the copy constructor in all cases.
"Dizzy" <di***@roedu.ne twrote in message
news:45******** *************** @news.sunsite.d k...
lovecreatesbea. ..@gmail.com wrote:
>With g++ (GCC) 3.4.2 (mingw-special), line 21 doesn't create `o1' as type of `C' class. No default and copy constructions are called for this line. I don't understand this.
Simple, somewhere in the ISO C++ standard they say if some declaration ca
be
interpreted as a function declaration then it is a function declaration.
This combined with the (not very well known) fact that functions, besides
declaring them as you usually do: int func(float obj); you can also do it
with the following syntax (they are equivalent) int func(float(obj) );
That is true, but that is not why it's a function declaration _in this
particular case_. It would be the case if
C o1(C(o2));
was used, but the function parameter name (o2 in the above example) was
omitted, making it a function declaration that returns C, and accepts a
[function that returns C with no parameters] as a parameter.
- Sylvester
On Fri, 19 Jan 2007 19:34:29 +0800, Sylvester Hesp <s.****@oisyn.n lwrote:
int func(int x)=int func(int),so
int func(int())=int func(int func1(void))
....
--
Hello,World!
----legolaskiss. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
I'm trying to read up on the rfc's that govern form inputs. Much of
what I'm reading is stuff I didn't know before and some of it is
alarming. This one left with me questions:
http://www.ietf.org/rfc/rfc1867.txt
Is this (below) addressed to me as a web designer, or is this
addressed to the makers of web browsers? Identifying the type of file
being uploaded seems way outside of my scope as a PHP coder. Am I
|
by: greenflame |
last post by:
I have been working for some time on a script that will show a matrix
with the elements aligned on the right for sometime and finally got it
to work. Then I did some patching up and ran the script and it showed a
blank page and no error in the status bar. The script is rather long
and I call functions that do things that I may not need the functiosn
for but they are there because I so that task so many times that I jsut
made it into a...
|
by: Lance Geeck |
last post by:
I have many items that I lifted off from Microsoft's website several years
ago. These samples were in VB6.
I now want to convert an application to VB.NET. I am getting an error
that says "As Any is not supported in a declare statement" during the
automated
Conversion process.
Some examples of this are:
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory"(ByRef
|
by: Benjamin Lukner |
last post by:
Hi!
I'd like to dynamically call API functions from different DLLs,
depending on what platform the program runs. Now I'm wondering what the
most simple way may be (without meta code and compiler switches!).
I'd like to call it like that:
Public Sub xyz()
|
by: Altman |
last post by:
I am having problems with Declaring a function from a dll. I had it work in
VB 6 but I can't get it to work in VB.net. This was the call in VB6
Public Declare Function MBTConnect Lib "MBT" (ByVal szHostAddress As String,
ByVal port As Integer, ByVal useTCPorUDP As Long, ByVal requestTimeout As
Long, hSocket As Long) As Long
When I try this in VB.net I get the following Error:
"Object Reference not set to an instance of an object"
...
| |
by: Tany |
last post by:
How can I declare function returning array of Integer pointers . Please
help !!
|
by: benben |
last post by:
How do you declare a function f that takes a parameter that is a pointer
to itself?
So you can do f(f);
Pardon my curiosity!
Ben
|
by: marss |
last post by:
How to declare function that accepts any generic list as input
parameter? I mean I need
void foo(List<list)
{
}
where:
Valid parameters are List<SomeInfo>, List<string>, List<Guid>, e.t.c.
Invalid parameters are SomeInfo, string, Array, ArrayList,
Dictionary<int, string>, e.t.c
|
by: dolphin |
last post by:
Hi All
I read a .cpp files,find that
static void fun(void){......}
int main()
{
..........
}
What does this static function mean?Is it the same as the static
|
by: zzzxtreme |
last post by:
hi i built a very simple dll with delphi
library Printing;
uses
SysUtils, Classes, Dialogs;
{$R *.res}
function Hello: WideString; stdcall;
begin
ShowMessage('test');
result := 'blah';
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |