|
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..
|
|
|
|
|
Software_Specialist wrote: I guess L is used to helt converting from const char to TCHAR*...pls correct me if i am wrong.
Yeah, I forgot to mention the main stuff...
When declaring strings for use with CString, wrap them in _T( "" )
Here it will be
const TCHAR* strSource = _T( "All files(*.*)|*.*||" );
|
|
|
|
|
ok kewl...
...got it working now...
So now i should always use TCHAR in place of char and for this i just have to include TCHAR.h and no need to define anything. It would work with UNICODE as well as non-UNICODE.
gr8....thanks a lot
|
|
|
|
|
Software_Specialist wrote: Now when i am writing code for UI, i have to use function strlen, strcpy , strcmp...
Why? The CString class provides all you need.
Software_Specialist wrote: So now do i have to change the whole application where i have used char.
Yes, since it is Unicode.
"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 don't know if anyone else mentioned this, but if you're going to go through all your code
and change it to work on Unicode, then I recommend in addition to changing all the char to TCHAR
also change all the CRT string calls to generics as well: strcpy = _tcscpy, strlen = _tcslen,
etc. instead of changing them to the wide character version.
That way all the code will be generic and you'll be able to reuse any code easier in any project
regardless of the character set settings.
It doesn't take that long to convert - I did a huge set of projects in a couple hours
MArk
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi all
well i have a lil problem here
I have created few classes and stuff and i have used normal char type variable.
Now when i am writing code for UI, i have to use function strlen, strcpy , strcmp...
For instance if i do...
<br />
char str[10];<br />
CString Password;<br />
strcpy(str, Password);<br />
In above code i get error saying can not convert parameter 2 from 'CString to const char*'
So to overcome this problem i made these changes as shown below...
<br />
wchar_t str[10];<br />
CString Password;<br />
wcscpy(str, Password);<br />
This solved my error but now i have many other errors. where i used char . So now do i have to change the whole application where i have used char. All the functions and stuff..
Is it now compulsory to use unicode in MFC....??? I am new to MFC so new to Unicode thingy..bit confusing though..
Can any one shed some light over this..
Any or all help would be greatly appreciated..
Thanks a lot
|
|
|
|
|
if you define _UNICODE you have to follow unicode. For CString to const char* error you could have used some macro for typecasting. no need to go for WCHAR. There are many other ways to e.g. password.GetBuffer(Password.GetLength()); which will return yoi char *.
|
|
|
|
|
oh i wasn't aware of this.I already started changing stuff and error seems to be never ending. Hmm i got a backup of project though... So i guess i need to start it again.
Well i have not define _UNICODE...and what could be solution you could think of in the problem i mentioned.
Can we still use unicode without defining _UNICODE. I guess we can cos few things are working when i changed to wchar_t and i have not defined _UNICODE anywhere...
Thanks
|
|
|
|