473,500 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What causes foo().fun() objects?

I wish I had an example so I could demonstrate. This is something I've
wanted to understand for a long time, but every time I've hit it, I've been
too busy to stop and investigate. Sometimes when I try to construct
objects of class type, I end up with weird things that look like
foo().fun(). I believe it happens like this:

Foo foo();
foo.fun();

After the call to foo.fun(); I get an error showing me I have some kind of
object called foo(). If I don't use the "()" in the constructor, that
fixes the problem. Does anybody know what I'm talking about?
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Dec 15 '06 #1
5 1438
Hi

Steven T. Hatton wrote:
Foo foo();
foo.fun();

After the call to foo.fun(); I get an error showing me I have some kind of
object called foo(). If I don't use the "()" in the constructor, that
fixes the problem. Does anybody know what I'm talking about?
Yes, you are looking for:
http://www.parashift.com/c++-faq-lit....html#faq-10.2

Markus

Dec 15 '06 #2

"Markus Moll" <mo**@rbg.informatik.tu-darmstadt.dewrote in message
news:45**********************@newsspool3.arcor-online.net...
Hi

Steven T. Hatton wrote:
Foo foo();
foo.fun();

After the call to foo.fun(); I get an error showing me I have some kind
of
object called foo(). If I don't use the "()" in the constructor, that
fixes the problem. Does anybody know what I'm talking about?

Yes, you are looking for:
http://www.parashift.com/c++-faq-lit....html#faq-10.2

Markus
And this, which explains it better:
http://www.parashift.com/c++-faq-lit...html#faq-10.19
Dec 15 '06 #3
Steven T. Hatton wrote:
Sometimes when I try to construct objects of class type, I end up
with weird things. I believe it happens like this:

Foo foo();
This is not the correct syntax to construct an object of class type.
(Spending too much time on Java?)
foo.fun();

After the call to foo.fun(); I get an error showing me I have some kind of
object called foo(). If I don't use the "()" in the constructor, that
fixes the problem.
Foo foo;

is the correct syntax for constructing an object via the default
constructor.

Dec 15 '06 #4
Old Wolf wrote:
Steven T. Hatton wrote:
>Sometimes when I try to construct objects of class type, I end up
with weird things. I believe it happens like this:

Foo foo();

This is not the correct syntax to construct an object of class type.
(Spending too much time on Java?)
>foo.fun();

After the call to foo.fun(); I get an error showing me I have some kind
of
object called foo(). If I don't use the "()" in the constructor, that
fixes the problem.

Foo foo;

is the correct syntax for constructing an object via the default
constructor.
There has to be more to this, because it rarely happens to me. I'll have to
wait till it happens again to see if I can figure out why I'm doing things
differently, or why the code is acting unusually. It may simply be
flashbacks to Java. But I think there's more to it. I believe it has
happened when I do something like:

Blah * blah_ptr(new Blah());

//but

Blah * blah_ptr(new Blah);

//works.

The pointers to the FAQ were informative. They may even answer the whole
question.
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Dec 15 '06 #5
"Steven T. Hatton" <ch********@germania.supwrote in message
news:Nt******************************@speakeasy.ne t
Old Wolf wrote:
>Steven T. Hatton wrote:
>>Sometimes when I try to construct objects of class type, I end up
with weird things. I believe it happens like this:

Foo foo();

This is not the correct syntax to construct an object of class type.
(Spending too much time on Java?)
>>foo.fun();

After the call to foo.fun(); I get an error showing me I have some
kind of
object called foo(). If I don't use the "()" in the constructor,
that fixes the problem.

Foo foo;

is the correct syntax for constructing an object via the default
constructor.

There has to be more to this, because it rarely happens to me. I'll
have to wait till it happens again to see if I can figure out why I'm
doing things differently, or why the code is acting unusually. It
may simply be flashbacks to Java. But I think there's more to it. I
believe it has happened when I do something like:

Blah * blah_ptr(new Blah());

//but

Blah * blah_ptr(new Blah);

//works.

You are allowed to have brackets when you use new, but not when you don't
use new (since the use of new enables the compiler to better distinguish
your intent).

struct S
{
S()
{cout << "S default constructor\n";}
};

struct Foo
{
Foo(S *ptr)
{ cout << "Foo\n";}
};

struct Goo
{
Goo(const S & ref)
{
cout << "Goo\n";
}
};
int main()
{
Foo foo(new S()); // works OK
Goo goo(S()); // function declaration with no effect

return 0;
}
--
John Carson

Dec 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3539
by: Michele Simionato | last post by:
So far, I have not installed Prothon, nor I have experience with Io, Self or other prototype-based languages. Still, from the discussion on the mailing list, I have got the strong impression that...
4
3825
by: Jacek Dziedzic | last post by:
Hi! First of all, I hope my problem is not too loosely tied to the "standard C++" that is the topic of this group. I have some code that exhibits a strange behaviour: on one computer, where I...
5
2219
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
34
4421
by: Jorge | last post by:
Why is it listed here : http://www.crockford.com/javascript/recommend.html under "deprecation" ? Without it, how is an anonymous function() going to call itself (recursively) ? I use to...
0
7136
marktang
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,...
0
7182
Oralloy
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,...
0
7232
jinu1996
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...
1
6906
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...
0
5490
agi2029
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,...
1
4923
isladogs
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...
0
1430
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 ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.