Hi, guys.
I am reading the C++ faq this days. When I am reading the faq 10.19, i
am not quite sure about it. I tested the code in my VC 6.0, and it
works fine. Who is right? The faq author or the comiler? My personal
preference would be the author. But could someone explain the issue
more clearly for me? I do not quite understand the explanation in the
faq, especially this sentece "When the compiler sees Foo x(Bar()), it
thinks that the Bar() part is declaring a non-member function that
returns a Bar object, so it thinks you are declaring the existence of a
function called x that returns a Foo and that takes as a single
parameter of type "non-member function that takes nothing and returns a
Bar."
The faq is http://www.parashift.com/c++-faq-lit...html#faq-10.19
My code for test:
#include <iostream>
using namespace std;
class Bar {
public:
Bar() {}
};
class Foo {
public:
Foo(const Bar& b) {} // or perhaps Foo(Bar b)
void blah() {std::cout << "hi\n";}
};
int main()
{
Foo x(Bar());
x.blah();
} 4 1122
mimi wrote:
Hi, guys.
I am reading the C++ faq this days. When I am reading the faq 10.19, i
am not quite sure about it. I tested the code in my VC 6.0, and it
works fine. Who is right? The faq author or the comiler?
The FAQ. It appears that VC 6.0 is broken.
My personal
preference would be the author. But could someone explain the issue
more clearly for me? I do not quite understand the explanation in the
faq, especially this sentece "When the compiler sees Foo x(Bar()), it
thinks that the Bar() part is declaring a non-member function that
returns a Bar object, so it thinks you are declaring the existence of a
function called x that returns a Foo and that takes as a single
parameter of type "non-member function that takes nothing and returns a
Bar."
That sounds correct.
The faq is http://www.parashift.com/c++-faq-lit...html#faq-10.19
My code for test:
#include <iostream>
using namespace std;
class Bar {
public:
Bar() {}
};
class Foo {
public:
Foo(const Bar& b) {} // or perhaps Foo(Bar b)
void blah() {std::cout << "hi\n";}
};
int main()
{
Foo x(Bar());
x.blah();
}
This should not compile. You can try your code at: http://www.comeaucomputing.com/tryitout
Best
Kai-Uwe Bux
mimi wrote:
Hi, guys.
I am reading the C++ faq this days. When I am reading the faq 10.19, i
am not quite sure about it. I tested the code in my VC 6.0, and it
works fine. Who is right? The faq author or the comiler? My personal
preference would be the author. But could someone explain the issue
more clearly for me? I do not quite understand the explanation in the
faq, especially this sentece "When the compiler sees Foo x(Bar()), it
thinks that the Bar() part is declaring a non-member function that
returns a Bar object, so it thinks you are declaring the existence of a
function called x that returns a Foo and that takes as a single
parameter of type "non-member function that takes nothing and returns a
Bar."
The faq is http://www.parashift.com/c++-faq-lit...html#faq-10.19
My code for test:
#include <iostream>
using namespace std;
class Bar {
public:
Bar() {}
};
class Foo {
public:
Foo(const Bar& b) {} // or perhaps Foo(Bar b)
void blah() {std::cout << "hi\n";}
};
int main()
{
Foo x(Bar());
x.blah();
}
I wouldn't be surprised that VC6 accepts it, the question remains
whether it accepts it within norms. g++ definitely fails it with the
description provided.
I like his explanation, he is saying that Foo x(...) is declaring a new
function. And it is!
Foo x(const Bar& r_bar)
{
std::cout << "function Foo x(...)\n";
return Foo(r_bar);
}
int main()
{
Foo x(Bar());
x(Bar()).blah();
}
/*
Bar()
function Foo x(...)
Foo::blah()
*/ ewww
* mimi:
Hi, guys.
I am reading the C++ faq this days. When I am reading the faq 10.19, i
am not quite sure about it. I tested the code in my VC 6.0, and it
works fine. Who is right? The faq author or the comiler? My personal
preference would be the author. But could someone explain the issue
more clearly for me? I do not quite understand the explanation in the
faq, especially this sentece "When the compiler sees Foo x(Bar()), it
thinks that the Bar() part is declaring a non-member function that
returns a Bar object, so it thinks you are declaring the existence of a
function called x that returns a Foo and that takes as a single
parameter of type "non-member function that takes nothing and returns a
Bar."
The faq is http://www.parashift.com/c++-faq-lit...html#faq-10.19
My code for test:
#include <iostream>
using namespace std;
class Bar {
public:
Bar() {}
};
class Foo {
public:
Foo(const Bar& b) {} // or perhaps Foo(Bar b)
void blah() {std::cout << "hi\n";}
};
int main()
{
Foo x(Bar());
x.blah();
}
VC6 is a very old compiler, not quite standard-conforming.
Later versions of Visual C++ do not accept that code.
As long as Greg Comeau is willing to provide that service, you can
always test code like that with Comeau Online, an online version of the
Comeau C++ compiler (probably the most standard-conforming one); of
course it also rejects the above.
--
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?
"Kai-Uwe Bux дµÀ£º
"
mimi wrote:
Hi, guys.
I am reading the C++ faq this days. When I am reading the faq 10.19, i
am not quite sure about it. I tested the code in my VC 6.0, and it
works fine. Who is right? The faq author or the comiler?
The FAQ. It appears that VC 6.0 is broken.
You are right, I tried it in VC2005, and it can't be compiled. I think
i should go to my lovely gcc.Thank you for your reply.
My personal
preference would be the author. But could someone explain the issue
more clearly for me? I do not quite understand the explanation in the
faq, especially this sentece "When the compiler sees Foo x(Bar()), it
thinks that the Bar() part is declaring a non-member function that
returns a Bar object, so it thinks you are declaring the existence of a
function called x that returns a Foo and that takes as a single
parameter of type "non-member function that takes nothing and returns a
Bar."
That sounds correct.
The faq is http://www.parashift.com/c++-faq-lit...html#faq-10.19
My code for test:
#include <iostream>
using namespace std;
class Bar {
public:
Bar() {}
};
class Foo {
public:
Foo(const Bar& b) {} // or perhaps Foo(Bar b)
void blah() {std::cout << "hi\n";}
};
int main()
{
Foo x(Bar());
x.blah();
}
This should not compile. You can try your code at:
http://www.comeaucomputing.com/tryitout
Best
Kai-Uwe Bux
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: abbas reji |
last post by:
--0-599929911-1059996886=:4358
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Content-Id:
Content-Disposition: inline
________________________________________________________________________
|
by: Piotre Ugrumov |
last post by:
I have some problems and some doubts.
I have implemented a class hierachy. The base class Velivolo, from Velivolo
derive Militare and Civile, from militare derive Aereo and Elicottero, from
Civile derive Passeggero e Merce. In every class I have implemented the
overload of << and >>. In a class Simulator (not in hierachy) I have
implemented...
|
by: ranjeet.gupta |
last post by:
Dear All
Below are the few doubts which I got while studying about C
1. Is there any method in C by which we can process the entire string
in one unit,
2. Does there exist any way to make the command line arguments
available to other functions without passing them as arguments to
|
by: maadhuu |
last post by:
hello everybody,
i have 2 doubts .
1. is this always defined ??
int i =10;
int a = i++ + i++;
and also, i tried this in gcc, answer was 20, so what the sequence points
for evaluation of something like i++ + i++ ???
|
by: Chua Wen Ching |
last post by:
Hi there,
I have some questions to ask... just say i have this xml file:
Scenario :-
Script.xml
========
<software>
<settings>
| |
by: VMI |
last post by:
I'm having doubts as to how the compiler interprets this If statement:
bool bIsTrue = true;
if (! bIsTrue)
{
//RUN PROCESS
}
Here, will "RUN PROCESS" be executed? Or is this just wrong? How is this
|
by: NagaKiran |
last post by:
Hi
I want to post VBA related doubts.
Where can I post my doubts in VBA?
thanks
bye
|
by: lovecreatesbeauty |
last post by:
Hello experts,
I have seen following the code snippet given by Marc Boyer (with slight
changes by me for a better format), and have doubts on it. I am so
grateful if you can give me your kindly help and hints on this problem.
1. Does the function call `foo(3, 3, tab);' refer to the data outside
the array `int tab;'. The available...
|
by: ramasubramanian.rahul |
last post by:
hi
i was trying to see how the compiler hides the static golbals from the
linker and allows golbal varibale to be visable to the linker.i managed
to figure out how it did that ( the .lcomm and .comm sections) but the
assembly code for the c program raised a few more doubts . i am
enclosing the .c and the .s files .. if someonce could expain...
|
by: ramasubramanian.rahul |
last post by:
hi people..
dont know if this the right forum for this doubt ... so sorry if i am
mis-posting...
i was looking at the way glib 2.10.3 does export optimization using a
list of "to be exposed" function names in a file caleed glib.symbols.
this file is used by a perl script to generate a header a .c file
( galias.h and galiasdefs.c). This...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
| |