|
Hi all!
I'm having a problem when compiling this code:
template<class t=""> inline CImage operator-(T value)<br />
{<br />
CImage tmpImage(CImagePtr(NULL));<br />
<br />
switch ( getDepth() )<br />
{<br />
case IMAGE_DEPTH_32F:<br />
SubtractFloat(getImage(),tmpImage.getImage(),value,false); <br />
break;<br />
default:<br />
SubtractInt(getImage(),tmpImage.getImage(),value,false);<br />
}<br />
return tmpImage;<br />
}<br />
<br />
inline CImage operator-(CImage& imageB)<br />
{<br />
CImage tmpImage(ImagePtr(NULL)); <br />
Subtract(getImage(),imageB.getImage(),tmpImage.getImage());<br />
return tmpImage;<br />
}<br />
</class>
SubstractFloat substracts one constant "value" (float) from a CImage. SubstractInt does the same with int type. And Substract substracts a CImage from a CImage.
I'm calling these functions as this way, for example:
CImage imResult;<br />
double minVal = 50;<br />
imResult = imResult-minVal;
This code was running and compiling without problems in VC++6.0. Now, in 7.0 the compiler is throwing me these errors:
error C2664: 'SubtractFloat' : cannot convert the parameter 3 from 'Icar::CImage' to 'float'<br />
error C2664: 'SubtractInt' : cannot convert the parameter 3 from 'Icar::CImage' to 'int'
If I force a cast to (double)value the compiler then says that there isn't an operator defined for double.
Thanx for your help. Every idea is welcome!
|
|
|
|
|
How aer declared (and defined) SubtractFloat and SubtractInt ?
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
|
|
|
|
|
IPLAPI(void, SubtractS,(CImage* srcImage, CImage* dstImage, int value, BOOL flip))
IPLAPI(void, SubtractSFP,(CImage* srcImage,CImage* dstImage,float value,BOOL flip))
|
|
|
|
|
Provided the operators are methods of CImage class, I see no problems in 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
|
|
|
|
|
The operators are methods of CImage, the Substract procedures no.
Here is the problem, the code compiles well under vc++6 but not under vc++7.
modified on Wednesday, April 23, 2008 10:29 AM
|
|
|
|
|
Template support in VC++ 6.0 is poor. It was improved a lot in VC++ 7.0 hence lot of code which used to work in VC++ 6.0 doesn't work in VC++ 7.0.
jonnyvargazz wrote: template inline CImage operator-(T value)
Why do you have template without parameters in the function definition? It should be
template<typename t=""> inline CImage operator - (T value)</typename>
-Saurabh
|
|
|
|
|
Sorry I had an error writing the header. The correct is:
template<class T> inline CImage operator - (T value)
No, no, it seems that the "<class T>" didn't displayed well.
|
|
|
|
|
Hi did you able to solve the problem. It seems somehow type of T is being initialized to CImage but is not obvious with the code you posted. Can you share the how you define the class CImage.
-Saurabh
|
|
|
|
|
I think the problem is that the compiler interprets that if there is an operator definition with a Cimage parameter, and then is an override with a template parameter, the basic parameter is a CImage, and it has no possibilities about reinterpret the parameter as a number.
For the moment I've took out the template, and declared the override with a size_t parameter. It's enough for me at the moment, I think, because this declarations could run with every kind of numeric params. Isn't it?
Thank you very much!
|
|
|
|
|
I tried to test this with a simple class with just two operators similar to yours. I works fine and I got no errors. So I am not sure where is the problem.
-Saurabh
|
|
|
|
|
CImage class is using a CImage namespace. May it has something relative to the problem.
|
|
|
|
|
I'm developing an animated game on Win32.
my message-loop looks like this:
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
CPTWindowManager::GetInstance()->RenderAllGames();
}
}
I have noticed that takes 50% of the CPU.
I wonder if this 50% are "for real". If so, it is not desirable.
I tried to use GetMessage() but I don't know how to figure out the "idle" state when using GetMessage() .
Note that the rendering stuff are relatively simple rendering and thus the time they take is unnoticeable.
|
|
|
|
|
No matter how long the "rendering stuff" is taking, you have a busy loop all the time: there's nowhere a 'pause' in the loop (sleep or wait for something...). But don't worry too much, that's usually how games are written: you want to achieve the best possible performance, so it's normal that you will eat up all remaining CPU time.
In your case it is probably taking 50% of the CPU because you have a dual-core, am I right ?
|
|
|
|
|
Yes I have a dual-core.
Also, I don't 'feel' the 50% slowing down my windows experience.
I have, however, saw a similar game that when run only eats several %.
Perhaps they did some scheme with the WM_PAINT messages - they cause the window to refersh, by InvalideRect() I guess, and render on the WM_PAINT s.
Sound like something I should try ?
Thanks
|
|
|
|
|
It depends which kind of game it is. For example, if it is something static (like solitaire, mine sweeper, ...) then you don't need to repaint the view dynamically. You can simply repaint the view when something changed.
So, I can't really answer your question, it depends of the kind of game you are trying to write.
|
|
|
|
|
Thanks.
It has dynamic rendering, to be specific, it plays series of pictures according to time (what might be called animation).
So it must repaint all the time.
|
|
|
|
|
Helo,
i m writing socket application.
my socket server application is running on linux machine.
now i write a client socket application in windows vc++ using winsock API.
I want to use openssl with winsock API.
does winsock and openssl work fine. if not then , what is better option in vc++ to create client socket application with openssl.
tell me , what API i have to use in windows-vc++ so that i can use openssl
Regards,
Amit
|
|
|
|
|
CP search engine answer [^]
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
|
|
|
|
|
I have 3 files:
1. main.exe
2. rar.exe (the console version of winrar)
3. test.rar
main.exe will call rar.exe to extract text.rar.
Now, I'd like to make ONE install file with the 3 files, any way?
The easier the better, thanks.
|
|
|
|
|
AFAIK, installer-making tools (they're making one file that deploys the project) take care of the compression themselves. Try finding such free tool and just read how to use it. Because what your trying to do in not unusual.
|
|
|
|
|
As already said to you by another CPian, the installers themselves take care of the compression part. You can try NSIS or Inno Setup.
Or, if there's a reason why you would want to do it the way you said, how are you going to ensure the presence of winrar at the target machine? Or, are you going to ship winrar as well? I think that is an overkill.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
All right, I'll ship rar.exe(the console version, only one file).
Because this is a patch, it needs to find a right directory to install.
|
|
|
|
|
|
neha.agarwal27 wrote: I want to convert my "LPCSTR" string to "CString ", how can i do so?
LPCSTR lpText = "Some text";
CString cs( lpText );
|
|
|
|
|
I wonder how lazy people have become just because they can get free help. You did not try something as simple as this before asking it on the internet:
LPCSTR str = "I'm the dumbest";
CString szStr = str;
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|