|
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
|
|
|
|
|
If you don't want it sizeable, don't add the flags to make it sizeable - it's all in the documentation.
If you for some reason want a thick border (or sizebox, both are the same and both implies sizeable) but still want to prohibit the user from resizing the window (for whatever, malicious or not, reason), override the handling of WM_NCCALCSIZE.
It's spelled "Please", not PLZ.
|
|
|
|
|
thanks for ur consideration. i have find flags but could not find any if u know any let me know too.
|
|
|
|
|
I have an array of characters and I am trying to delete certain elements. The array conatains information about a file and has numerous blank and null spaces. I want to delete all of the null psces out of the array and also delete blank spaces that repeat throughout the array. I have an 'if' statement setup that recognizes if there are consecutive blank spaces or a null space. What is the command to then delete or remove the element at that point in the array. Thanks for the help.
Josh
|
|
|
|
|
as for as i know there is no way to delete the characters from array.better option is to take another array of chars and copy the non-null and non-blank chars to it. sorry if u dont like it.
|
|
|
|
|
I am pretty sure I know how to copy the elements to the other array. But the examples I have seen omit all of the characters that are not needed. I want to omit all of the null spaces, but I do need some of the blank spaces in order to separate words. Am I just trying to make this to complicated? I have found myself doing that a lot lately.
Josh
|
|
|
|
|
As a matter of fact u can "delete" the characters from the array, all u have to do is to copy the next character over the one u want it deleted, and that's it.
It's up to u to test if the next xharacter should be copied or left alone!
Papa
Murex Co.
|
|
|
|
|
You could use something like this:
delete_char(char* buffer,size_t length_buffer,size_t index)
{
memmove(buffer+index,buffer+index+1,length_buffer-index-1);
} Be aware this is very unefficient for large arrays, though it probably won't matter for the sizes you're handling.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello everybody,
Right now I'm creating an opengl activex control that allows JavaScript to communicate with the control. For example:
*********************************************
function begin()
{
var object = document.SGLworld;
object.StartRender();
}
function stop()
{
var object = document.SGLworld;
object.StopRender();
}
<object classid="clsid:4E14E2C5-A05D-466D-979A-97391CB899E8" width="200" height="200" id="SGLworld">
*********************************************
I plan on having the ability to pass class or struct objects back to a JavaScript variable like this:
*********************************************
function returnclass()
{
var box;
var object = document.SGLworld;
box = object.CreateBox(1.0, 1.0, 1.0); // return the createbox structure to the javascript variable(box)
box.SetColor(1.0, 0.0, 0.0); // now the varible(box) should have access to the structers members functions
}
*********************************************
But the problem is I have no clue how to pass struct(or class) objects back to a js variable! So if anybody has an idea or can redirect to some information I’d be very grateful!!!
Thanks,
Caleb
|
|
|
|
|
Have you tried SpiderMonkey? It's the javascript engine of the Mozilla project.
|
|
|
|
|