|
I don't work very often with that kind of things but I think that template specialization only works at the class level, not at the method level: you need to specialize your class and there, you can override the functions you like.
I think, in your situation it will be like this:
template <typename B><br />
class CMyClass<MyTypeName,B><br />
{<br />
};
I'm not 100% sure thought, so you'll have to check.
|
|
|
|
|
And what about ...?
template < class A, class B >
class CMyClass < A, B >::foo (class A1)
{
if (A1->IsKindOf (RUNTIME_CLASS ( A )))
else
}
EDIT: I actually am not sure if I understand the question right. A bit more info would be nice.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
sure...in that way it could work, but I prefere to use a simple "template specialization" it works well if all typename s must be specialized. But this is the first time that I have to specialize only a typename , so I I'm trying to find the correct sintax.
thanks for your time
Russell
|
|
|
|
|
I'm trying... I'll tell you the results tomorrow.
thanks
Russell
|
|
|
|
|
Hi,
I have found out (the hard way!) that you can't have a .cpp file with your function definitions if you are using a template class. All your function definitions must be in the .h file. Why is this?
Thanks for any info.
|
|
|
|
|
You can put the code in a C++ file, you just need to change how you define your templates.
I would not recommend that though, justuse a header file it's much easier.
regards,
|
|
|
|
|
Hi,
Thanks for that, but do you know why the C++ compilier objects to having function definitions in the .cpp ?
Thanks.
|
|
|
|
|
AFAIK it is because template code is generated by your compiler. It means that when you have a template instantiation (something like list<float> ) your compiler will generate code corresponding to this template type. To be able to generate the code, it needs the complete function implementation.
|
|
|
|
|
You do *not* have to have definitions in th ecpp.
You do this to (partially) separate interface and implementation.
With templates, every instantiation (for type A, type B etc) creates a new, distinct type: vector<A> is different from vector<B>.
And for this instantiation, the compiler needs the complete definition of the template. Therefore it is easiest to put the template in the header, to have it ready when you need it.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Yes, all in the .h file.
Only specializations must be putted in the .cpp file (declaraion, of course, in the .h file).
minkowski wrote: Why is this?
I think that this has only a reason related to how the compiler works to elaborates the templates.
I hope that this isn't a problem for you.
Russell
|
|
|
|
|
minkowski wrote: Why is this?
See here[^]
|
|
|
|
|
I have a list control of CListCtrl type and it has 3 columns. I want to hide the first column(of course, it will work internally). Is it possible?
|
|
|
|
|
Just out of curiosity, why do you need/want to do this?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Cant you make it of zero width?
- NS -
|
|
|
|
|
How about setting the width of that column to zero?
MS
|
|
|
|
|
Can you more explain why you need to do it?
|
|
|
|
|
plz tel the Difference between debug and release builds.
|
|
|
|
|
the basic difference is the debug information will be embedded in the exe in debug build which is not possible in release build.is it suficient or are u looking for anything else.
|
|
|
|
|
Another difference is that debug mode can maybe work perfectly, but same code in release may crush in hundreds of places.
Debug assumes some things when nothing is said, or automatically correct some errors of intialization.
Release executes ONLY what the programmer has written. If it is not correctly written will crush.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Read this.
Also, there is an artice on the CodeProject I think but I can't remember its name.
|
|
|
|
|
|
Speed is the main difference a debug build will by default have no optimisation, this makes it easier to debug. But you can debug a release build it is just a little harder.
|
|
|
|
|
|
Hi
In my program i want to use
<br />
BOOL MapAndLoad(<br />
PSTR ImageName,<br />
PSTR DllPath,<br />
PLOADED_IMAGE LoadedImage,<br />
BOOL DotDll,<br />
BOOL ReadOnly<br />
);<br />
function in Imagehlp.h .
<br />
CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath)<br />
{ LOADED_IMAGE loi;<br />
::MapAndLoad((LPSTR)(LPCTSTR)fileName, (LPSTR)(LPCTSTR)filePath, &loi,FALSE, TRUE);<br />
int i = loi.NumberOfSections;<br />
char q[50];<br />
sprintf(q,"%d",i);<br />
MessageBox(NULL, q,NULL,0);<br />
}<br />
When i compiled and execute it. It gives error Messagebox with value -858993460 . I changed my projects setting use multibyte character set. wchar_t to char.
But can not find solution. What is wrong with this code?
How can i fix it?
Thanks.
|
|
|
|
|
sawerr wrote: What is wrong with this code?
You did not check the return value from MapAndLoad() , nor did you call GetLastError() .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|