|
Try to replace the function definition (.cpp file) with:
template < class T >
TTEST < T >::TS * TTEST < T >::test1()
{
return NULL;
}
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.
|
|
|
|
|
Hi, CPallini. I have tried this way before, and failed with a similar error, in vc.
|
|
|
|
|
Strange, it works fine on my system (VS6).
Are you sure the sintax was the same?
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.
|
|
|
|
|
Yuwen Zhou wrote: I have tried this way before, and failed with a similar error, in vc.
Then you must've made a type-o. Simply qualifying TS is all that's needed.
"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
|
|
|
|
|
I think it has nothing to do with templates. I thnk in the CPP file you need to put TTEST::TS *, because the struct is defined inside the class.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I think u should modify the code as following:
<br />
1:
2: struct TS<br />
3: {<br />
4: int i ;<br />
5: } ;<br />
6: template < class T ><br />
7: class TTEST<br />
8: {<br />
9: public:<br />
10: TS t;<br />
11: public:<br />
12: TS* test1() ;<br />
13: } ;<br />
14:
15: #include "a.h"<br />
16: template < class T ><br />
17: TS* TTEST < T >::test1()<br />
18: {<br />
19: return NULL;<br />
20: }<br />
|
|
|
|
|
thanks for focusing ! I agree with you that it will work in your way, but to put TS's definition inside class TTEST will be more preferable.
|
|
|
|
|
Remeber you cannot implement a templated class's member functions in a separate .cpp file. You have to put the implementation in the .h file along with the class definition. Try moving all your original TTEST code into the .h file and see if it compiles them.
This is a limitation of C++ compilers which I can't at the moment remember the excuse for. You may need to ask Mr Stroustrup
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
haha, thx for focusing, Matthew ! I am afraid Mr Stroustrup will be too busy to reply me. I know the way to separate a template into .h & cpp files. You could search it inside codeproject(I couldn't remember the exact link).
|
|
|
|
|
Probably Mr.Stroustrup don't know that C++ Compiler is so smart to generate function using only declarations
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.
|
|
|
|
|
Hi all, after my searching around the web, I have found solution of my problem. Correct codes are shown bellow:
<br />
1:
2: template < class T ><br />
3: class TTEST<br />
4: {<br />
5: public:<br />
6: struct TS<br />
7: {<br />
8: int i ;<br />
9: } ;<br />
10: public:<br />
11: TS* test1() ;<br />
12: } ;<br />
13:
14: #include "a.h"<br />
15: template < class T ><br />
16: typename TTEST < T >::TS* TTEST < T >::test1()<br />
17: {<br />
18: return NULL;<br />
19: }<br />
pls notice line 16, a function "typename"(it is considered as a function in MSDN) was added between the "template < >" and the function return type, since the compiler can only recognise TTEST < T >::TS as a data type in this way. On the other hand, I could use class TTEST in my caller function just by simply include the a.cpp file instead of a.h in my own source file.
|
|
|
|
|
Hi
#include<memory.h>
#include<iostream.h>
class CStack
{
public:
void push()
{
cout<<"push";
}
};
int main()
{
auto_ptr<CStack> pt( new CStack );
return 0;
}
For this code I'm getting error
: error C2065: 'auto_ptr' : undeclared identifier
what header file should i include for auto_ptr.
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
try
#include <memory>
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.
|
|
|
|
|
Ya i have included that header file.But i am getting error:
E:\C++\ClassPointer\ClassPointer.cpp(14) : error C2065: 'auto_ptr' : undeclared identifier
=================================================
E:\C++\ClassPointer\ClassPointer.cpp(14) : error C2275: 'CStack' : illegal use of this type as an expression
E:\C++\ClassPointer\ClassPointer.cpp(4) : see declaration of 'CStack'
E:\C++\ClassPointer\ClassPointer.cpp(14) : error C2065: 'pt' : undeclared identifier
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
OK.
try the following:
#include <memory>
using namespace std;
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.
|
|
|
|
|
Thanks.Its now fine.
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
I want to use the hotkey combination of CTRL+ALT+F1, ...F2, ...F3 but although in my application I register these hotkeys thus:
... ::OnInitDialog()
...
RegisterHotKey( GetSafeHwnd(), ID_HELP_CONTENTS, MOD_CONTROL | MOD_ALT, VK_F1 );
...
I deregister the hotkeys in the destructor as well.
and I am capturing the message WM_HOTKEY these hotkeys do not work! I have registered other hotkeys just fine, and even if I change the above to capture say CTRL+ALT+B that works fine. Do I need to capture the key combination CTRL+ALT+F1 in a different way?
|
|
|
|
|
Andy H wrote: I am capturing the message WM_HOTKEY these hotkeys do not work! I have registered other hotkeys just fine, and even if I change the above to capture say CTRL+ALT+B that works fine. Do I need to capture the key combination CTRL+ALT+F1 in a different way?
What does GetLastError say? Or use @err,h r in the debugger and debug through to find out what happens when you call RegisterHotKey .
On my machine on pressing Ctrl + Alt + F1 it pops up windows help dialog.
|
|
|
|
|
Thanks.
I GetLastError() returns 1409 which equates to "Hot key is already registered".
|
|
|
|
|
Is it possible to hook into an existing hotkey combination, without having to go down to the WinMain?
|
|
|
|
|
Andy H wrote: Is it possible to hook into an existing hotkey combination
This[^] should help. Second question is yours.
Let me tell you that it's quite annoying to override an existing hotkey, imagine somebody doing the to your hotkey, be polite and choose another one.
Andy H wrote: without having to go down to the WinMain
I didn't get you.
|
|
|
|
|
I totally agree. I have suggested that some different hotkeys are used. Thanks for the advice.
|
|
|
|
|
Never use char and wchar with CString class. Always use TCHAR based types.
For eg: LPCTSTR, LPTSTR, TCHAR . and of course TCHAR based functions like _tcscpy, _tcscmp, _tcscmpi, _tcsstr .
You will always encounter such problems if you switch between UNICODE and non UNICODE builds.
TCHAR makes switching easy. So always use TCHAR based types with CString .
if _UNICODE is defined then TCHAR expands to wchar_t else it expands to char .
|
|
|
|
|
Thanks a lot for all your informative replies...
Well ill now change it to TCHAR. I guess this should solve the problem. If not then ill ask up again...
cheers
|
|
|
|
|
Hi
well as you all said to use TCHAR. i tried it just now...and got some prob as shown below
<br />
TCHAR strFilter[1000];<br />
_tcscpy_s(strFilter, "All Files (*.*)|*.*||");<br />
And error i got is none of the 2 overloads could convert all the arguments type.
So to overcome this problem i did as shown below...
<br />
TCHAR strFilter[1000];<br />
const TCHAR *strSource = L"All Files (*.*)|*.*||";<br />
_tcscpy_s(strFilter, strSource);<br />
This solved the error but i guess L is UniCODE...What could i use in place of that.
I guess L is used to helt converting from const char to TCHAR*...pls correct me if i am wrong.
Can i use it in this ...? If not then what could be the solution of the above error..
|
|
|
|