S
Simon
Hi,
First of all I am not sure if the term 'weak type' is the right one.
But basically this is what I have:
// ------------------------------
#include "string.h"
#include <sstream>
class Weak
{
public:
Weak() : _d64Bit(0) {};
Weak( double d ){
_d64Bit = d;
std:stringstream o;
if ((o << d))
{
_sString = o.str();
}
}
Weak( const std::string& s ){
_d64Bit = atof( s.c_str() );
_sString = s;
}
Weak( const Weak& w ){
_d64Bit = w._d64Bit;
_sString = w._sString;
}
~Weak(){
}
Weak operator+( const Weak& data ) const{
double d = data._d64Bit + _d64Bit;
return Weak( d );
}
private:
double _d64Bit;
std::string _sString;
};
int main(int argc, TCHAR* argv[])
{
// this works as expected
Weak x = 5;
Weak y = "37";
Weak z = x + y;
// but this does not work.
Weak z1 = 5 + "37"; // = "42" && 42
}
// ------------------------------
How can I get the last operation to work?
I get no errors, the result is just "0" and 0.00
Many thanks
Simon
First of all I am not sure if the term 'weak type' is the right one.
But basically this is what I have:
// ------------------------------
#include "string.h"
#include <sstream>
class Weak
{
public:
Weak() : _d64Bit(0) {};
Weak( double d ){
_d64Bit = d;
std:stringstream o;
if ((o << d))
{
_sString = o.str();
}
}
Weak( const std::string& s ){
_d64Bit = atof( s.c_str() );
_sString = s;
}
Weak( const Weak& w ){
_d64Bit = w._d64Bit;
_sString = w._sString;
}
~Weak(){
}
Weak operator+( const Weak& data ) const{
double d = data._d64Bit + _d64Bit;
return Weak( d );
}
private:
double _d64Bit;
std::string _sString;
};
int main(int argc, TCHAR* argv[])
{
// this works as expected
Weak x = 5;
Weak y = "37";
Weak z = x + y;
// but this does not work.
Weak z1 = 5 + "37"; // = "42" && 42
}
// ------------------------------
How can I get the last operation to work?
I get no errors, the result is just "0" and 0.00
Many thanks
Simon