By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,515 Members | 1,772 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,515 IT Pros & Developers. It's quick & easy.

What the operator can be used without quantify with namespace?

P: n/a
I'm confused with the following small program. I looked at the
<complex> header file (gcc-3.3). operator* is defined in namespace std.
I'm wondering why the operator * can be used in the following program
even without quantify with namespace std.

Thanks,
Peng

#include <complex>

int main(int argc, char *argv[])
{
std::complex<double> a;
std::complex<double> b;
std::complex<double> c = a * b;
}

Nov 9 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

<Pe*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I'm confused with the following small program. I looked at the
<complex> header file (gcc-3.3). operator* is defined in namespace std.
I'm wondering why the operator * can be used in the following program
even without quantify with namespace std.

Thanks,
Peng

#include <complex>

int main(int argc, char *argv[])
{
std::complex<double> a;
std::complex<double> b;
std::complex<double> c = a * b;
}


Look up Koenig Lookup (ADL):
http://h21007.www2.hp.com/dspp/tech/...01,990,00.html
http://en.wikipedia.org/wiki/Koenig_Lookup

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>


Nov 9 '05 #2

P: n/a

Pe*******@gmail.com wrote:
I'm confused with the following small program. I looked at the
<complex> header file (gcc-3.3). operator* is defined in namespace std.
I'm wondering why the operator * can be used in the following program
even without quantify with namespace std.

Thanks,
Peng

#include <complex>

int main(int argc, char *argv[])
{
std::complex<double> a;
std::complex<double> b;
std::complex<double> c = a * b;
}

Argument Dependent Lookup (ADL).
A function name is looked up in the globally available namespaces and
the namespaces of its all arguments to find an exact matching
declaration.
Since a and b are of type std::complex<double>, the namespace std will
also be searched for finding exact declaration of *

Nov 9 '05 #3

P: n/a
I'm not sure if I understand your question but here's what I think...

operator * is a function of the class complex...

just like push_back is a function of vector.

when you use push_back, you dont do:
vec.std::push_back(..) // do not try this at home

So why would you do use std:: before * ???

Think about it

Eric
<Pe*******@gmail.com> a écrit dans le message de news:
11**********************@g44g2000cwa.googlegroups. com...
I'm confused with the following small program. I looked at the
<complex> header file (gcc-3.3). operator* is defined in namespace std.
I'm wondering why the operator * can be used in the following program
even without quantify with namespace std.

Thanks,
Peng

#include <complex>

int main(int argc, char *argv[])
{
std::complex<double> a;
std::complex<double> b;
std::complex<double> c = a * b;
}

Nov 9 '05 #4

P: n/a
oupss forget about my last message...

I was thinking about *=

"Eric Pruneau" <e.*******@sympatico.ca> a écrit dans le message de news:
GO********************@news20.bellglobal.com...
I'm not sure if I understand your question but here's what I think...

operator * is a function of the class complex...

just like push_back is a function of vector.

when you use push_back, you dont do:
vec.std::push_back(..) // do not try this at home

So why would you do use std:: before * ???

Think about it

Eric
<Pe*******@gmail.com> a écrit dans le message de news:
11**********************@g44g2000cwa.googlegroups. com...
I'm confused with the following small program. I looked at the
<complex> header file (gcc-3.3). operator* is defined in namespace std.
I'm wondering why the operator * can be used in the following program
even without quantify with namespace std.

Thanks,
Peng

#include <complex>

int main(int argc, char *argv[])
{
std::complex<double> a;
std::complex<double> b;
std::complex<double> c = a * b;
}


Nov 9 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.