|
|
use floor and ceil
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
First, thank you all for your answers, they are proving very helpful.
Now, however, I've encountered a different issue:
I get the right results from the floor function. However, when I do the final division (I'm getting this information from stepping through the code in the VC++ .NET Debugger):
//m_fAmount is a float
m_fAmount = 30679.000
iDivisor = 1000.0000
m_fAmount / iDivisor yields: 30.679001
I am really puzzled as I'd like to think that the compiler can do simple arithmatic However, in all seriousness, what's causing this, I'm really puzzled.
Any and all help is greatly appreicated.
Thanks,
BP
|
|
|
|
|
It's caused by round-off errors in decimal->binary->decimal conversion.
|
|
|
|
|
Do you know where I can find some information on that error and how to compensate?
Thanks,
BP
|
|
|
|
|
Just say we're working in decimal with 4 places after the decimal point. Using this scheme we can represent the following numbers exactly:
1.0000
3.0000
But it we try to divide them:
1.0000/3.0000 = 0.3333
This answer is wrong already, the correct answer us 0.333333.... (the 3 recurs forever).
So now consider this sum:
(1.0000/3.0000)*3.0000 = 0.9999
This sort of things happens in all floating or fixed point numbering systems. The computer uses base 2 and not base 10 however.
Try using double instead of float ; there is seldom a good reason to prefer a float over a double
Steve
|
|
|
|
|
|
Greetings Colleagues,
I have a quick question. How do you return an object by value?
The following code:
<br />
MyObject MyClass::operator+(const MyClass & mcRhs)<br />
{<br />
MyClass mcNewObject();<br />
return mcNewObject;<br />
}<br />
results in the following error: c++ error C2664: No constructor could take the source type, or constructor overload resolution was ambiguous
It says it can't convert it. Ironically, when I leave the parentheses off of the instantiation of mcNewObject, it works!? Can someone please explain.
Thanks a million.
Sincerely,
BP
|
|
|
|
|
Can you post the definitions of the two classes?
Or... what line was the error on?
Mike
|
|
|
|
|
Thanks for replying,
This is the actual function
<br />
CNumber CNumber::operator+(const CNumber & cnThisNumber)<br />
{<br />
if((m_bIsBlank) || (cnThisNumber.ReturnIsBlank()))<br />
{<br />
CNumber cnBlankNumber();<br />
return cnBlankNumber;<br />
}<br />
else<br />
{<br />
float fReturnAmount;<br />
cnThisNumber.GetAmount(fReturnAmount);<br />
fReturnAmount = m_fAmount - fReturnAmount;<br />
CNumber cnNewAmount(fReturnAmount);<br />
return cnNewAmount;<br />
}<br />
}<br />
This is the copy constructor I have defined...
<br />
CNumber::CNumber(const CNumber & cnThisNumber) : m_iMaxDecimals(10)<br />
{<br />
cnThisNumber.GetAmount(m_fAmount);<br />
cnThisNumber.GetOriginalAmount(m_fOriginalAmount);<br />
m_bFormatChange = cnThisNumber.ReturnFormatChange();<br />
m_bIsZero = cnThisNumber.ReturnIsZero();<br />
m_strStringAmount = cnThisNumber.ReturnStringAmount();<br />
m_bIsBlank = cnThisNumber.ReturnIsBlank();<br />
}<br />
If I change "CNumber cnBlankNumber()" in the operator overload to "CNumber cnBlankNumber" it works. I just don't get it.
|
|
|
|
|
I don't get the () thing, but try doing return CNumber; or return CNumber(); .
Also - do you have a default constructor defined?
Mike
|
|
|
|
|
I will try that, and yes I do have a default constructor defined.
Thanks,
BP
|
|
|
|
|
BlitzPackage wrote: It says it can't convert it. Ironically, when I leave the parentheses off of the instantiation of mcNewObject, it works!? Can someone please explain.
Because C++ is not C# or Java. Look up how you define an object in C++ using the default ctor.
|
|
|
|
|
MyClass mcNewObject();
is a function declaration I think (Mike Dunn pointed that out to me via this forum when I did a similar thing a while back when trying to test constructor behavior a while back. Silly me )
|
|
|
|
|
This is a 'Ping' Message just to Ensure my ID
LateNightsInNewry
|
|
|
|
|
Hi all,
I have a problem with DateTimepicker Control in VC6.
If I choose the DTS_SHOWNONE style how can i get a notification if the user disable the DateTimeCtrl by unchecking the small checkbox that appears inside the control.
Please help me!
Thanks a lot.
snow
|
|
|
|
|
if we select the control style (DTS_SHOWNONE)
It is possible to have no date currently selected in the control. With this style, the control displays a check box that users can check once they have entered or selected a date. Until this check box is checked, the application will not be able to retrieve the date from the control because, in essence, the control has no date. This state can be set with the DTM_SETSYSTEMTIME message or queried with the DTM_GETSYSTEMTIME message.
|
|
|
|
|
Im not sure its helpful for you but see here[^]
|
|
|
|
|
I have developed a simple dialog based GUI and was attempting to link some C-code to it in the CDialog class i.e. copying the C code into the file and updating the header files. However, when I started to compile it, the following errors were encountered. I have not done anything with the MFC header files and know that it cannot be due to the program. It might be the way I inserted the c code into the GUI application. Please advise. Thanks.
c:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2238: unexpected token(s) preceding ';'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2238: unexpected token(s) preceding ';'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2238: unexpected token(s) preceding ';'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(122) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2802: static member 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2333: 'new' : error in function declaration; skipping function body
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2802: static member 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2556: 'void *(__cdecl *__stdcall CNoTrackObject::operator new(void))(unsigned int,const char *,int)' : overloaded function differs only by return type from 'void *(__c
decl *__stdcall CNoTrackObject::operator new(void))(unsigned int)'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : see declaration of 'new'
d:\code\jm\ldecod\inc\defines.h(22) : warning C4005: 'TRACE' : macro redefinition
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(218) : see previous definition of 'TRACE'
AVCDlg.cpp
c:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2238: unexpected token(s) preceding ';'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2238: unexpected token(s) preceding ';'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2238: unexpected token(s) preceding ';'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2059: syntax error : 'newline'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(122) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2802: static member 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2333: 'new' : error in function declaration; skipping function body
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2802: static member 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2556: 'void *(__cdecl *__stdcall CNoTrackObject::operator new(void))(unsigned int,const char *,int)' : overloaded function differs only by return type from 'void *(__c
decl *__stdcall CNoTrackObject::operator new(void))(unsigned int)'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : see declaration of 'new'
OO KM
|
|
|
|
|
plz send ur code ...what is in .cpp file and .h file ...so we encounter ur mistake
|
|
|
|
|
See here[^] maybe it is some helpful to you
|
|
|
|
|
First I glad that your problem solve and I guess you are a student
(1)I think best help is MSDN(From the MSDN)
"If either /Yc or /Yu is specified with /YX, a warning is issued. In such cases, /YX is ignored, and /Yc or /Yu takes precedence".
For more information see
here[^]
(2)can you be more specific,I saw many errors with error LNK2001
|
|
|
|
|
You are right. I am a student but an old one. This is the first time linking C code with C++ code. Normally, I used only C++ and it is simply using the defined classes.
I have this GUI that was developed and this C-code that performs image processing. I have copied the main() code to the GUI and declared the global variables in the dialog class.
The image processing files are brought into the workspace and the GUI made dependent on these files. No problem on compiling. However, during the linking up, there are some extern variables in the image processing files that need referencing to. They are declared in the Dialog cpp file. That is the reason for the "unresolved external symbol _img" and the strings of other error message.
I have included the Dialog.h in the source file of the image processing file and they could not recognize the class terms i.e. more error occurred.
2nd question is the declaration of C- code in a C++ program. Can I use this method? The two functions are C functions.
afx_msg void decode(void);
afx_msg void Configure(void);
Thanks a lot for your time and advise. Greatly appreciated.
searcher08
|
|
|
|
|
Student,I was student and I know when a student has a problem he trys to find his problem(anyway I couldnt found my answer )But I have a question why you want to use c code is it possible for you to write your code on C++.
|
|
|
|
|
I can't use C++ coz the c code was developed by another person and I have to add in the GUI and perform improvement on the code. To recode that will take too long.
I have already spent hours on this problem and I am not getting anywhere. I think the answer is out there except that it is not made known.
Thanks.
searcher08
|
|
|
|