|
rp_suman wrote: How to cast a float expression into int safely without data loss?
float f;
f = whatever;
int i = *(int *)&f;
Of course it is only a technical exercise and probably not what you're searching for.
BTW you should know that real numbers cannot mapped to countable (i.e. integers) ones, someone proved that [^].
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
|
|
|
|
|
to insert a space in a string,when it is reversed.
|
|
|
|
|
Insert a space into what? Can you be precise? Why can't you give an example, with input and desired output?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
What does being reversed have to do with a space being inserted? From the STL, use the string::insert() method, and the reverse() function.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
how are you reversing the string!?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hi to ALL
have one doubt regarding with my project .
our project goal is to create one user dll(this dll create for VC 2005) and in this dll load another one java platform (via jni compiler.. it is possible)
first up all .i was create DLL when i attached this dll in JNI compiler its perfectly running in windows XP (it gives return value '0')but in vista it is also running but it gives the return value '255'
for example i give one method to our source :
STDMETHODIMP CFileIO::fileExist(BSTR filePath, BYTE drive, SAFEARRAY* credential, BYTE* result)<br />
{<br />
*result = (BYTE)-1;
std::string completePath;
try<br />
{<br />
validateCredential(credential);<br />
setPath(filePath, drive, completePath);
}<br />
catch (std::exception& e)<br />
{<br />
log("fileExist", e.what(), EVENTLOG_ERROR_TYPE);<br />
return S_OK;<br />
}<br />
size_t zz = completePath.rfind("\\");<br />
if (zz < completePath.length())<br />
{<br />
std::string dirOnly = completePath.substr(0,zz);<br />
<br />
DWORD nBufferLength = 1024;
TCHAR buffer[1024];<br />
<br />
LPTSTR* lpFilePart = NULL;<br />
<br />
DWORD searchResult = SearchPath(<br />
dirOnly.c_str(),<br />
completePath.substr(zz+1, completePath.length()).c_str(),<br />
NULL,<br />
nBufferLength,<br />
buffer,<br />
lpFilePart<br />
);<br />
if (searchResult > 0)<br />
{<br />
*result = (BYTE)1;<br />
}<br />
else<br />
{<br />
*result = (BYTE)0;<br />
}<br />
}<br />
return S_OK;<br />
}
#define S_OK ((HRESULT)0x00000000L)
#define S_FALSE ((HRESULT)0x00000001L)
//in winerror.h
This perfectly running in windows XP it gives the return value '0' but in vista it gives the reurn value '255'
i need your answer..
*****THANKS N ADVANCE****
Mathen.K
(I WILL TRY MY LEVEL BEST )
|
|
|
|
|
See here[^].
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I think he mean the value in *result
|
|
|
|
|
Naveen wrote: I think he mean the value in *result
I don't get a thing of what he says. Please feel free to help him, if you understand his query.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I already did. See here[^]. He post the question under an article of mine
|
|
|
|
|
rowdy_vc++ wrote: i need your answer..
What answer are you looking for? You are assigning -1 (which is 255 for unsigned types) to result . Until it is assigned some other value, it will remain as such.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Dear group,
I have to load all the dependent libraries of an ELF output file while it is loading.
SO for this i decided to write ELF parser to load the dependent libraries.
Please suggest me with a sample.
Thanks in advance,
Ravinder Are
Are
|
|
|
|
|
You need a Unix-oriented forum.
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
|
|
|
|
|
Google for readelf and then look at the source for it
Judy
|
|
|
|
|
There are large number of gamers who play lan based games using GG-framework. Even I play Warcraft with other guys on internet.
But GG (Now Garena) client software does not seem to add any adapter or
driver for creating the virtual lan. I used netstat to find out, there
are two 'ESTABLISHED' TCP connections when I log in to GG.
When one logs in to GG, one has to start the game through this client and viola! one can see all the game servers and one can play as if the other guys are on lan with him.
How this is possible? Anyone got ideas?
|
|
|
|
|
Hello everyone,
About the virtual function design pattern mentioned,
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.4
I do not quite understand what does this statement mean "Assuming they're protected, they probably shouldn't be virtual: if the derived class doesn't like the behavior in one of them, it doesn't have to call that method." Any ideas?
I quote the whole paragraph here,
--------------------
Suppose you have the exact opposite situation from the previous FAQ, where you have a method whose overall structure is different in each derived class, yet it has little pieces that are the same in most (if not all) derived classes. In this case you'd put the overall algorithm in a public virtual that's ultimately defined in the derived classes, and the little pieces of common code can be written once (to avoid code duplication) and stashed somewhere (anywhere!). A common place to stash the little pieces is in the protected part of the base class, but that's not necessary and it might not even be best. Just find a place to stash them and you'll be fine. Note that if you do stash them in the base class, you should normally make them protected, since normally they do things that public users don't need/want to do. Assuming they're protected, they probably shouldn't be virtual: if the derived class doesn't like the behavior in one of them, it doesn't have to call that method.
--------------------
thanks in advance,
George
|
|
|
|
|
I think it means that if a function is not designed to be over-ridden by its derived classes, it should not be virtual.
|
|
|
|
|
Thanks followait,
From what I quoted, which part indicates "a function is not designed to be over-ridden", which type of functions mentioned in the quoted parts indicates "a function is not designed to be over-ridden"?
regards,
George
|
|
|
|
|
Yes. They represent (in class hierarchy designer mind) simple unit of common behaviour, for instance:
class Base
{
public:
virtual void do_things();
protected:
void do_common1();
void do_common2();
bool test_common();
};
class Derived: public Base
{
public:
virtual void do_things();
};
Base::do_things()
{
}
Derived::do_things()
{
do_something_specific();
do_common1();
do_something_else_specific();
if ( test_common() )
{
do_common2();
}
else
{
do_something_specific3();
}
}
If Derived class designer doesn't like do_common1 behaviour, he (or she) can replace it with another piece of code, specific of do_things implementation of Derived class. This help to keep the overall project architecture cleaner, because common behaviours remain unchanged through class hierachy, while changes happen inside methods deliberately designed for the purpose. Roughly speaking it is a granularity problem: keep little common behaviours invariant.
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
|
|
|
|
|
Thanks CPallini,
What harm will be if we make the following 3 methods virtual? I think the design architecure is still clean as your sample without code change, right?
void do_common1();
void do_common2();
bool test_common();
regards,
George
|
|
|
|
|
George_George wrote: What harm will be if we make the following 3 methods virtual?
Actually no harm.
George_George wrote: I think the design architecure is still clean as your sample without code change, right?
Nope. In original design there is a (conventional) clean distinction between invariant pieces of (common used) code and methods designed to exploit polymorphism.
If you make the above methods virtual (and even if you don't change the remaining code) then you imply that polymorphism may happen on these little pieces of (common used) code. The developer examining Derived::do_things() method then should be aware that changes may are not only inside the method logic itself but also inside its 'elementary' commonly used blocks. This double-layered kind of polymorphism is not a mistake but doesn't contribute to project neatness.
BTW: As usual, this is going on my arrogant assumptions
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
|
|
|
|
|
Thanks CPallini,
So, you mean for the 3 non-virtual "common" methods, it means derived class and base class should share common code? So, making the 3 non-virtual "common" methods virtual will make developer confused about potential efforts to override and provide differences (polymorphism)?
regards,
George
|
|
|
|
|
George_George wrote: So, you mean for the 3 non-virtual "common" methods, it means derived class and base class should share common code?
They are made for that purpose.
George_George wrote: So, making the 3 non-virtual "common" methods virtual will make developer confused about potential efforts to override and provide differences (polymorphism)?
It makes more difficult to interpretate do_thing() actual behaviour.
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
|
|
|
|
|
Thanks CPallini,
So, your answer and pattern to this question is, if code are common in both base and derived class, and derived class has no need to override it, do not make it virtual?
regards,
George
|
|
|
|
|
My answer to the question is slighty different: if small pieces of code are common in the hierarchy of classes (it applies mainly to complex class hierachies) then make those methods available to the whole class hierarchy (hence the base class is a good place for them) but don't make them virtual (if you don't need them, don't use them), leaving polymorphism be done in the right places, i.e. bigger methods (of course small and big tradeoff is subjective).
The above is, IMHO, the substance of the original text.
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
|
|
|
|