473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

implicite function call

Hi all c++ experts
I have a problem with determining why are certain functions called in
the given code example.
In main, fkcja1(one) [ void fkcja1(A as) ] is called, then in its body
it should call fkcja1(1) but actually B::B(int a) is called (WHY?) and
before returning from fkcja1(one) there is a call to
[ void fkcja1(B be) ] (WHY?)

Why there is no call to void fkcja1(int c) !

I'd be grateful for explaining or hint about language feature
responsible for this behaviour so I could dig for more info.

//code example
#include <iostream>
#include <stdio.h>
using namespace std;

class B;
class B {
public:
B();
B(int a);
};

class A {
public:
A();
fkcja1(B be);
};

void fkcja1(B be)
{
B next(1);
}

void fkcja1(A as)
{
B be(1);
fkcja1(1);
}

void fkcja1(int c)
{
cout << "E\n";
}

B::B()
{
cout << "C" << endl;
A next;
}

B::B(int a)
{
cout << "D\n";
}

A::A()
{
cout << "A\n";
}

int main()
{
A one;
fkcja1(one);
return 0;
}

Feb 11 '06 #1
2 1398
* manny:

Hi all c++ experts
There are probably only four or five C++ experts in the world.

I have a problem with determining why are certain functions called in
the given code example.
In main, fkcja1(one) [ void fkcja1(A as) ] is called,
Are you /sure/ you there is no better name for that function?

then in its body
it should call fkcja1(1) but actually B::B(int a) is called (WHY?)
Because you told it to,

void fkcja1(A as)
{
B be(1);

This calls B::B( int ) and

fkcja1(1); // X

this also invokes the B::B( int ) constructor.

}

and before returning from fkcja1(one) there is a call to
[ void fkcja1(B be) ] (WHY?)
At the point in the code where you have the call marked X above, the
only as-yet-encountered declaration of fkcja1 that is compatible with
the call, is fkcja1(B), via conversion of int to B.

Note that your declaration of a B member function called fkcja1 (which
is never defined) is unrelated to the three freestanding functions you
have also chosen to name fkcja1.

Why there is no call to void fkcja1(int c) !
Because that function is not yet declared, and thus unknown, at the
place you're trying to call it.

I'd be grateful for explaining or hint about language feature
responsible for this behaviour so I could dig for more info.

//code example
#include <iostream>
#include <stdio.h>
Don't #include headers you don't use.

using namespace std;

class B;
class B {
public:
B();
B(int a);
};

class A {
public:
A();
fkcja1(B be);
This member function is never defined anywhere.
};

void fkcja1(B be)
{
B next(1);
}

void fkcja1(A as)
{
B be(1);
fkcja1(1);
}
At this point only fkcja1( B ) is known.

void fkcja1(int c)
{
cout << "E\n";
}


Are you sure no better diagnostic output could be devised? ;-)

[snipped further code]
--
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?
Feb 11 '06 #2
Hi
thanks for quick response,
Of course the names are terrible (in fact it is not my code) and
includes are unnecessary, I'll do my best to not post again such ugly
code ;)
best regards
manny

Feb 11 '06 #3

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

Similar topics

11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
9
by: Morten Lemvigh | last post by:
Is it possible to pass a pointer to a constructor or a class definition as argument to a function? Maybe in a way similar to passing function pointers...? The function should construct a number...
7
by: Andrew Poulos | last post by:
Say I have this foo = function() { // blah }; bar = fuction(fnName) { /* If fnName equalled "foo" * How do I test that foo, as a function, * exists and then, if it exists, call it?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.