473,395 Members | 1,464 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,395 software developers and data experts.

What the operator can be used without quantify with namespace?

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
4 1355

<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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: franky.backeljauw | last post by:
Hello, I have a problem with using a copy constructor to convert an object of a templated class to object of another templated class. Let me first include the code (my question is below): ...
9
by: John Cho | last post by:
// CHO, JOHN #include<iostream> class fracpri{ int whole; int numer; int denom;
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
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...

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.