J
johny smith
I was defining one of my own math functions for sin. So I thought I would
create a unique name space. Then use that namespace in my program to call
my custom sin math function. That way I was hoping that I would not call
the math library math function but my own custom.
But it did not seem to work. Here is what I did.
in my.h file
#include <cmath>
namespace myMath {
double sin( double ); // this is a declaration for my custom function
}
in my .cpp file
#include "my.h"
namespace myMath {
double sin( double input ) // this is my custom math function
definition
{
stdio::cout << "my custom math function\n" << std::endl;
sin( input ); // this a call to the <cmath> library
}
}
using namespace myMath; // hopefully this will cause my custom sin function
to be called
int main()
{
// I was hoping this would call my math function sin not the <cmath>
function since I am using the myMath namespace.
std::cout << "the value is " << sin(.3) << std::endl;
return 0;
}
So, what am I doing wrong here?
Many thanks.
create a unique name space. Then use that namespace in my program to call
my custom sin math function. That way I was hoping that I would not call
the math library math function but my own custom.
But it did not seem to work. Here is what I did.
in my.h file
#include <cmath>
namespace myMath {
double sin( double ); // this is a declaration for my custom function
}
in my .cpp file
#include "my.h"
namespace myMath {
double sin( double input ) // this is my custom math function
definition
{
stdio::cout << "my custom math function\n" << std::endl;
sin( input ); // this a call to the <cmath> library
}
}
using namespace myMath; // hopefully this will cause my custom sin function
to be called
int main()
{
// I was hoping this would call my math function sin not the <cmath>
function since I am using the myMath namespace.
std::cout << "the value is " << sin(.3) << std::endl;
return 0;
}
So, what am I doing wrong here?
Many thanks.