|
Hi. I am also new in templates. I wrote a template class:
template<class t=""> class CExample
Now, I asked this before but am really confused.
I know that to declare it I do:
CExample<class t=""> m_Example;
What if I want to do this using "new"?
Is it
CExample<uint>* m_pExample;
m_pExample = new CExample<uint>;
Something like this???
Then to clean up:
delete m_pExample; (Anything special)
THanks in advance.
|
|
|
|
|
You need to check the "Display as-is" checkbox so the template params show up properly.
Given this class:
template <class T> class CExample
{
public:
T increment(T t) { return ++t; }
}; you refer to the class later with CExample plus a typename which takes the place of T :
CExample<int>* pExampleInt = new CExample<int>();
pExampleInt->increment ( 123 );
delete pExampleInt;
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Hi Mike.
What do you mean by "Display as is?"
|
|
|
|
|
The checkbox below your post as you type it which says "Display this message as-is (no HTML)"
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
Hi all,
Can I rotate a CDialog (andd all its controls 90degrees (or 270 for that matter)?
How? Is it a matter of rotating the CDialog and then all controls within it will follow or do I have to do it one control at a time?
Don't ask why and , but can I do it?
TIA, Jose
|
|
|
|
|
No.
Well, yes, you can if you handle all the drawing yourself (and now we're speaking all NC painting also), intercepting and changing x&y mouse positions and so on.
But short of that? No. It would be easier to turn the screen 90 degrees to be unable to read it normally.
I won't ask "why angry and confused" (whatever that means).
|
|
|
|
|
Theoretically, you can draw anything on your screen, just derive your own dialog class from CDialog and override all the painting related methods.
|
|
|
|
|
I have seen many documentations on cutting, copying, pasting, filenames to and from Explorer into an App... but I do not understand how it is done. I am looking for source code to demonstrate it. If someone could please point me in the right direction, coded samples would be a great help. Thank you.
<><><><><><><><><><><><><><>
Matthew R. Miller
mattrmiller@computersmarts.net
www.computersmarts.net
|
|
|
|
|
Check out my article on drag & drop in the Shell section - it uses the same data format (DROPFILES) as copy/paste.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Ok, I'm a newbe when it comes to templates, even though I've been programming C/C++ for over 25 years. I just havn't gotton around to learning templates.
What I want to do is write a template string class that supports either char* and wchar_t* (but not necessarily at the same time). I know I can do this:
template<class type="">
class UStringT
{
public:
UStringT() { sptr = NULL; }
~UStringT() {if(sptr) delete[] sptr;}
TYPE c_str() {return sptr;}
void operator=(TYPE* string);
private:
TYPE* sptr;
};
So far, so good. Now the hard part -- how to use standard C/C++ library functions functions: for example, if I want the length of the string, it needs to call strlen() it TYPE is char*, or wcslen() if TYPE is wchar_t*. How do I put that logic in the template?
** This does NOT work ***
If TYPE == char
return strlen(string)
else if TYPE == wchar_t
return wcslen(string);
|
|
|
|
|
why are you not using std::string, which does all of this ?
Anyhow, the answer is template specialisation. You can write a length function defined differently for different values of TYPE.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
Thanks for the tip, Chris. I didn't know std::string could be used that way. This seems to work the way I want it to:
typedef basic_string<char> charA;
typedef basic_string<wchar_t> charW;
template<class TYPE>
class UStringT
{
public:
UStringT() { }
~UStringT() {}
const TYPE& c_str() {return sptr;}
void operator=(TYPE strng);
int length() {return sptr.length();}
private:
TYPE sptr;
};
int foo()
{
UStringT<charA> string1A;
UStringT<charW> string1W;
string1A = "Hello World";
string1W = L"Hello World";
return 0;
}
|
|
|
|
|
Yes, that is exactly how std::string works. Your class is superfluous, the two typedefs give you a wide and a narrow string. I believe there is a std::stringW ( or similar ) as well as std::string providing typedefs for the two templated types of std::basic_string already.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
That reminds me of one of my favorite "neat trick" macros:
typedef std::basic_string<TCHAR> tstring;
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
> template specialisation
is this thing supported in vc++...I remember people complaining the lack of it et al
Kannan
|
|
|
|
|
Specialization is (partially) supported. Partial specialization is however explicitly not supported at all, even in VC7.
|
|
|
|
|
Mike Nordell wrote:
Specialization is (partially) supported. Partial specialization is however explicitly not supported at all, even in VC7.
I would have to read it more than twice to understand what you where trying to tell. Thanks.
Kannan
|
|
|
|
|
Yes, specialization is supported. It's essentially overloading a template for a specific set of template params. Partial template specialization is one that's not supported (maybe it is "partially" - I still don't understand how it works).
template class CFoo<typename T>
{
public:
void DoStuff ( T t ) { ... }
};
template<> class CFoo<char>
{
public:
void DoStuff ( char ch ) { FormatDrive(ch); }
};
main()
{
CFoo<int> foo_int;
CFoo<char> foo_char;
foo_int.DoStuff(42);
foo_char.DoStuff('C');
} I think I have all the syntax right... templates are a PITA sometimes.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
i've never tried it before, how do i implement it?
thanks in advance.
|
|
|
|
|
Hi,
I'm writing a Win32 app (Non-MFC), is there a way i can implement linked lists without using CList (MFC)
|
|
|
|
|
You could use the STL equivilent, or just write your own linked list class. Its pretty easy to do.
|
|
|
|
|
CString m_string = "123.45221"
double the_double = (double)m_string;
iz not working.iz dat the right way to convert or type cast a CString object to double ??
|
|
|
|
|
<br />
#include <stdlib.h><br />
<br />
CString str = "123.45";<br />
double f = atof(str);
|
|
|
|
|
double strtod( const char *nptr, char **endptr );
Maxwell Chen
Lets make bugs better!
|
|
|
|
|
HI
I have created a window with CreateWindowEx and with toolbar style i want it to be fixed so that it cannot be resized. is there any special parameter to pass to make it fixed. PLZ do share the knowledge
|
|
|
|