Click to See Complete Forum and Search --> : How to create conversion of independent types?
vgrigor3
June 9th, 2003, 07:34 AM
Code like this
double n =0;
CTime(n);
generates warning
"warning C4244: 'initializing' : conversion from '__time64_t' to 'double', possible loss of data"
probably need to write a conversion to make compiler
notified that conversion proceed through redefined way -
loss of data is in aware of program.
How to write this, with probably no inherit from
that types - due many code already written,
and will be looking no well readable with so many conversions.
Using SmartPointers only?
PaulWendt
June 9th, 2003, 08:19 AM
Why don't you create CTime in the terms it can be created? Look
at this link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_ctime.3a3a.ctime.asp.
Note that you don't have the option to create a CTime object from
a double. So, convert your double to a type that you can create
a CTime from and then create the CTime object.
--Paul
vgrigor3
June 9th, 2003, 08:27 AM
This is due to problems:
first - this is common problem and I want have to know a solution.
second - code is written for a duoble, it was suitable for to see and to use format. Code desired to be not fully rewritten.
Milliseconds was not found in most of times,
except system time - but it was huje, no opearations (+, -) defined for this.
Direct operations as on seconds and parts of seconds is not presented. Does this correctl?
Doew problem can be solved not changing problem self to
much smaller subset.
typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
PaulWendt
June 9th, 2003, 01:35 PM
I don't really understand what you're saying. I think you mean
that you have some code that you guys use in-house which uses
double for your time types. You also want to use CTime so you
are trying to convert double to a CTime.
I think you're going to want to use CTime's interface to set it
based on your double. You could probably create a wrapper
function to do something like this:
CTime createTimeFromDouble(double ourTime)
{
CTime time;
time.setMonth(/*...*/);
// ...
return time;
}
vgrigor3
June 10th, 2003, 01:35 AM
No,
problem in no writing just working code-
(rewrite all method, even al works)
but "right" code -good readable,
once- changed for all-workable,
so there is much
code like I shown,
and need in one place, not changing all this occurencies,
eliminate warning - make the conversions approved by language.
Paul McKenzie
June 10th, 2003, 05:06 AM
Originally posted by vgrigor3
No,
problem in no writing just working code-
(rewrite all method, even al works)
but "right" code -good readable,
once- changed for all-workable,
so there is much
code like I shown,
and need in one place, not changing all this occurencies,
eliminate warning - make the conversions approved by language. You cannot do this. You either have to
a) derive a class from CTime and create a constructor that takes
a double,
OR
b) Create a class wrapper for CTime (derive a class that contains
a CTime object)
OR
c) Call a function that returns a CTime based on your double argument.
OR
d) Create a class that takes a double (call it DateDouble) and has
a conversion function that returns some argument that is
appropriate for CTime. Then instead of "double d = 1.0", you do
DataDouble d = 1.0;
CTime( d );
where DataDouble is a class that takes a double and has a
conversion operator that converts the 1.0 to the appropriate type.
Bottom line is that there is no magic bullet that will work the way
you want it to work. When you want to make a class take an
argument of your own choosing, you have no choice but to do
one of the four items above. The constructor for the original
class cannot be changed (unless you have the source code).
Regards,
Paul McKenzie
vgrigor3
June 10th, 2003, 05:20 AM
most good variant can picked
DataDouble d = 1.0;
CTime( d );
Probably I'll use this due to not double is not
standard time type and is used occasionally due to suitability,
in only intermediate places - for saving place and precision.
But else variants is desired -due to probably not all variants you
found in small time period and C++ is reach.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.