Steven said:
Julie wrote:
I'm not even sure the original assertion is correct. I am under the
impressionn that a using declaration will hide other instances of the
symbol so that using std::swap; will cause only std::swap() to be invoked
unless the other swap is specifically qualified.
What does this indicate?
#include <iostream>
using std:
stream;
using std::endl;
namespace assign_f {
float calc(float x, float y)
{
return x * y ;
}
}
namespace assign_i {
int calc(int x, int y)
{
return x + y;
}
}
namespace assign {
int acalc(int x, int y)
{
return x - y;
}
float acalc(float x, float y)
{
return y!=0? x/y: 0;
}
}
void t1(ostream& out,
const int& i1,
const int& i2,
const float& f1,
const float& f2 ) {
using assign_i::calc;
int i = calc(i1,i2);
out << i << endl;
float f = calc(f1,f2);
out << f << endl;
}
void t2(ostream& out,
const int& i1,
const int& i2,
const float& f1,
const float& f2 ) {
using assign_f::calc;
int i = calc(i1,i2);
out << i << endl;
float f = calc(f1,f2);
out << f << endl;
}
void t3 (ostream& out,
const int& i1,
const int& i2,
const float& f1,
const float& f2 ) {
using assign::acalc;
int i = acalc(i1,i2);
out << i << endl;
float f = acalc(f1,f2);
out << f << endl;
}
int main(int argc, char* argv[]) {
using std::cout;
int i1 = 10;
int i2 = 8;
float f1(i1);
float f2(i2);
t1(std::cout, i1,i2,f1,f2);
t2(std::cout, i1,i2,f1,f2);
t3(std::cout, i1,i2,f1,f2);
}
hattons@ljosalfr:~/code/c++/scratch/assign/src/
Wed May 26 17:16:39:> g++ -o assign main.cc
main.cc: In function `void t1(std:
stream&, const int&, const int&, const
float&, const float&)':
main.cc:41: warning: passing `const float' for argument passing 1 of `int
assign_i::calc(int, int)'
main.cc:41: warning: argument to `int' from `const float'
main.cc:41: warning: passing `const float' for argument passing 2 of `int
assign_i::calc(int, int)'
main.cc:41: warning: argument to `int' from `const float'
main.cc: In function `void t2(std:
stream&, const int&, const int&, const
float&, const float&)':
main.cc:53: warning: initialization to `int' from `float'
main.cc:53: warning: argument to `int' from `float'
hattons@ljosalfr:~/code/c++/scratch/assign/src/
Wed May 26 17:17:15:>./assign
18
18
80
80
2
1.25