|
CPallini wrote: The same (VC6) compiler gives the correct result on such a comparison.
CPallini wrote: xb211 wrote:
As i'm doing some comparison for example:
if(a>b){
//a might be 0.666666667890 in java
//b might be 0.666666667590 in java
//a might be 0.666666667890 in c++
//b might be 0.666666667590 in c++
and c++ won't detect that a is greater than b
}
I meant...
the result I have from c++
a: 0.000000 b: 0.166667
a: 0.166667 b: 0.166667
the result from java
a: 0.0 b: 0.16666641666679166
a: 0.16666658333320838 b: 0.16666641666679166
when comparing a and b...
the 2nd case, c++ will say they are the same whereas in Java, it says they are different.
|
|
|
|
|
I suppose something is lost in traslation.
Check your code.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I just wrote:
double testing = 0.1242923758275093850928390582;
cout << "testing: " << testing << endl;
printf("testing: %f\n",testing);
output:
testing: 0.124292
testing: 0.124292
*** edited ***
I added:
#include <iomanip>
cout << "testing: " << setprecision(20) << testing << endl;
printf("testing: %f\n",testing);
testing: 0.12429237582750939
testing: 0.124292
But.. how do i set the variable itself to have precision of 20 (for example)?
|
|
|
|
|
Interesting.
Try the following with the good old (euphemism) VC6 compiler:
#include "stdafx.h"
#include <iostream.h>
#include <iomanip.h>
void main()
{
double testing = 0.1242923758275093850928390582;
cout << "testing: " << setprecision(23) << testing << endl;
printf("testing: %25.23f\n",testing);
}
</iomanip.h></iostream.h>
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I did:
double testing = 0.1242923758275093850928390582;
double testing1 = 0.1242923758275093850929390582;
or
long double testing = 0.1242923758275093840928390582;
long double testing1 = 0.1242923758275093940929390582;
if(testing1>testing){
cout << "YAY" << endl;
}
it doesn't print out "YAY"
|
|
|
|
|
And what about the Java behaviour with the same inputs?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ehh.. oops.. i need to re-look at my code! ![Poke tongue | ;-P](https://www.codeproject.com/script/Forums/Images/smiley_tongue.gif)
|
|
|
|
|
PROBLEM SOLVED! it was some initialization issue.
in c++... i passed in a fraction ~ 2/3 = 0.66666666666666666666667 (for example)
in java... i passed in 0.6666666667
What was I thinking huh?
Thanks for all the help! Really appreciate it! ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Your welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
i have a Sdi with a splitter (4 rows).
When i click on the maximize button the window is maximized and the 1. splitter row changes its height proportionally , but when i try to restore, nothing happens with the Splitter ;(.
Please help me !
Here is my code:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
int iCurRow_cy = 0, iMin_cy = 0;
static int iOldWnd_cy = 0, iOldWnd_cx = 0;
int iNewCurRow_cy = 0;
static int iZaehler = 0;
static CString a, b, c, d;
iZaehler++;
if (iZaehler == 1)
{
iOldWnd_cy = cy;
a.Format("%02d",iOldWnd_cy);
b.Format("%02d",cy);
c.Format("%02d",iCurRow_cy);
d.Format("%02d",iNewCurRow_cy);
MessageBox("iOldWnd_cy: "+ a + "\ncy: " + b + "\niCurRow_cy: " + c + "\niNewCurRow_cy: " + d,"in: iZaehler == 1 " ,MB_OK);
}
if ((nType == SIZE_MAXIMIZED))
{
m_Splitter_Main.GetRowInfo(0 ,iCurRow_cy, iMin_cy);
iNewCurRow_cy = (int)ResizeSplitter(cx, cy, iOldWnd_cx, iOldWnd_cy, iCurRow_cy, 1);
a.Format("%02d",iOldWnd_cy);
b.Format("%02d",cy);
c.Format("%02d",iCurRow_cy);
d.Format("%02d",iNewCurRow_cy);
MessageBox("iOldWnd_cy: "+ a + "\ncy: " + b + "\niCurRow_cy: " + c + "\niNewCurRow_cy: " + d,"in: SIZE_MAXIMIZED " ,MB_OK);
m_Splitter_Main.SetRowInfo(0, iNewCurRow_cy , 0);
m_Splitter_Main.RecalcLayout();
}
else if((!m_Splitter_Main.m_hWnd && nType == SIZE_RESTORED))
{
m_Splitter_Main.GetRowInfo(0 ,iCurRow_cy, iMin_cy);
iNewCurRow_cy = (int)ResizeSplitter(cx, cy, iOldWnd_cx, iOldWnd_cy, iCurRow_cy, (1));
a.Format("%02d",iOldWnd_cy);
b.Format("%02d",cy);
c.Format("%02d",iCurRow_cy);
d.Format("%02d",iNewCurRow_cy);
MessageBox("iOldWnd_cy: "+ a + "\ncy: " + b + "\niCurRow_cy: " + c + "\niNewCurRow_cy: " + d,"in: SIZE_RESTORED " ,MB_OK);
m_Splitter_Main.SetRowInfo(0, iNewCurRow_cy , 0);
m_Splitter_Main.RecalcLayout();
}
CFrameWnd::OnSize(nType, cx, cy);
}
double CMainFrame::ResizeSplitter(int cx, int cy, int iOldWnd_cx, int iOldWnd_cy, int iCurRow_cy, int iZahl)
{
double iNewCurRow_cy;
double iDiff;
double iFaktor;
CString ccc;
CString ddd;
CString aaa;
CString bbb;
iDiff = cy - iOldWnd_cy;
iFaktor = iDiff / cy;
iNewCurRow_cy = (iCurRow_cy * ((iFaktor)+(iZahl)));
return iNewCurRow_cy;
Many, many thanks !
Best regards !
Croc
|
|
|
|
|
REALLY NOBODY !!!???
Best regards
Croc
|
|
|
|
|
Have you tried handling WM_WINDOWPOSCHANGED?
This is called whenever you minimize, maximize, restore or move. I reckon you'll get away with
making the code in your onSize handler respond to WM_WINDOWPOSCHANGED instead of WM_SIZE.
modified on Sunday, October 12, 2008 8:44 AM
|
|
|
|
|
THX enhzflep,
i'll try it !!!
Best regards
ShadowEater
|
|
|
|
|
Look at the following piece of code:
class IAbstractBase
{
public:
virtual void funca() = 0;
};
class IAbstractDerived : public IAbstractBase
{
public:
virtual void funcb() = 0;
};
class BaseImpl : public IAbstractBase
{
public:
void funca() { }
};
class DerivedImpl : public BaseImpl, public IAbstractDerived
{
public:
void funcb() { }
};
void some_func()
{
DerivedImpl* x = new DerivedImpl();
}
The compiler now tells me that i can't instanciate DerivedImpl, because funca() has no implementation. What i don't understand is that funca() is defined in BaseImpl, which is a base class of DerivedImpl, but the compiler doesn't care about that.
Here is the exact compiler output:
------
.\Test.cpp(33) : error C2259: 'DerivedImpl' : cannot instantiate abstract class
due to following members:
'void IAbstractBase::funca(void)' : is abstract
.\Test.cpp(6) : see declaration of 'IAbstractBase::funca'
------
Any idea for a solution of that problem? ![Confused | :confused:](https://www.codeproject.com/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|
Why do you use the (slighty modified) diamond inheritance pattern? could you avoid it, couldn't you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I don't think that it is really a diamond.
Please look at my answer at: (link)[^]
|
|
|
|
|
Andreas Kilian wrote: What i don't understand
Multiple inheritance diamond problem[^]
Andreas Kilian wrote: Any idea for a solution of that problem?
No because that depends on your requirements which you have not provided. Essentially you need a different design which of course is based on the requirements.
led mike
|
|
|
|
|
The diamond:
IAbstractBase
/ \
/ \
BaseImpl AbstractDerived
\ /
\ /
DerivedImpl
Andreas Kilian wrote: Any idea for a solution of that problem?
You could maybe use virtual inheritance, but be sure
it's what you want (that's why this code throws a warning)...
class IAbstractBase
{
public:
virtual void funca() = 0;
};
class IAbstractDerived : public <code>virtual</code> IAbstractBase
{
public:
virtual void funcb() = 0;
};
class BaseImpl : public <code>virtual</code> IAbstractBase
{
public:
void funca() { }
};
class DerivedImpl : public BaseImpl, public IAbstractDerived
{
public:
void funcb() { }
};
I have a feeling that may not be what you want...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi!
I don't think that it is a classical diamond because IAbstractBase and IAbstractDerived are pure virtual. I think my problem is that i've been programming Java and C# for too long. In those languages the classes IAbstractBase and IAbstractDerived were interfaces. Java code would look like:
interface IAbstractBase {}
interface IAbstractDerived extends IAbstractBase {}
class BaseImpl implements IAbstractBase {}
class DerivedImpl extends BaseImpl implements IAbstractDerived {}
this is totally legal and works fine in Java. I just adopted that design and took "pure virtual classes" in C++ as what is called an "interface" in Java (and C#).
I rewrote the code to:
class IAbstractBase { };
class IAbstractDerived : virtual public IAbstractBase { };
class BaseImpl : virtual public IAbstractBase { };
class DerivedImpl : public BaseImpl, virtual public IAbstractDerived { };
Virtual inheritance solves the compiler error. What i've done is using virtual inheritance for all pure virtual classes. But i still get a warning:
.\Test.cpp(34) : warning C4250: 'DerivedImpl' : inherits 'BaseImpl::BaseImpl::funca' via dominance
.\Test.cpp(24) : see declaration of 'BaseImpl::funca'
I'm sure i can safely ignore this warning because there's only one inheritance path which has function implementations (and data members). All other add just pure virtual functions.
But thanks for you anser! Your hint to virtual inheritance solved my problem. ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
This isn't java - The inheritance paths with multiple inheritance
in C++ are separate (so I guess it's a pyramid, not a diamond)
Anyway, both inheritance paths have to implement any pure virtual
functions along the path, unless you use virtual inheritance.
Andreas Kilian wrote: I'm sure i can safely ignore this warning
If you'd like, you can disable it for that code with
#pragma warning disable 4250 // disable "'DerivedImpl' : inherits 'BaseImpl::BaseImpl::funca' via dominance"
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey everybody!
How do I get the domain's SID???
I looked all over the web for that, and I also checked the WMI.
Any help with that, anyone???
Thanks!
|
|
|
|
|
Green Fuze wrote: How do I get the domain's SID???
You mean this?[^]
led mike
|
|
|
|
|
Yeah!
Thanks!
and with that, I also found ConvertSidToStringSid() to get it to string.
But how do I get the the account SID needed for GetWindowsAccountDomainSid???
thanks a lot! again!
|
|
|
|
|
Nevermind, got that ![Smile | :)](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Hello All,
I am trying to write a program who acts as client and server both, first it connects to the main server and then can communicate with other clients directly and can maintain connection with the main server simeltaneously.
Can anyone help on this please? Its really urgent.
Thanks.
|
|
|
|