|
You don't have to call DrawMenuBar() . You aren't the owner of the menu, Explorer is, so calling that function isn't your responsibility.
|
|
|
|
|
Does the string class have something similar to the split() functionality available in the .Net framework? or would I have to actually split the string manually by looping through the character array?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
The STL string class doesn't have a split function.
Mustafa Ismail Mustafa wrote: would I have to actually split the string manually by looping through the character array
You could do that, or you could do yourself a favour and use the split function in the Boost string algorithm library[^]. If you end up doing it manually, though, you'll probably benefit from using the STL string's find_first_of method?
|
|
|
|
|
Gaa, you beat me to it! I'm not fast enough
Florin Crişan
|
|
|
|
|
Sorry for the late reply but I had to leave for a bit. Thanks I was contemplating installing boost, but I figured I'd hit the standard STL before I do that. Besides, this is only for my MSc. PoC for my Advanced Algorithms lecture.
As is, many thanks to you and Florin!
However, I'm now facing something new.
This is a partial view of what I have:
try
{
ListOfSubsets().push_back("{}");
list<char*>::iterator pos;
for(pos = ListOfElements().begin(); pos != ListOfElements().end(); ++pos)
{
cout << *pos << endl;
}
}
catch(exception ex)
{
cout << "an error has occurred: " << endl;
cout << ex.what() << endl;
return;
}
with these defined in the header:
private:
list<char*> _ListOfElements;
list<char*> _ListOfSubsets;
protected:
list<char*> ListOfElements(void) const
{
return _ListOfElements;
}
void set_ListOfElements(list<char*> listOfElements)
{
_ListOfElements = listOfElements;
}
list<char*> ListOfSubsets(void) const
{
return _ListOfSubsets;
}
void set_ListOfSubsets(list<char*> listOfSubsets)
{
_ListOfSubsets = listOfSubsets;
}
It builds no problem, but when it runs, at the start of iterating through the list ListOfElements, it throws the following error:
Debug Assertion failed! Expression: list iterators incompatible.
no exception is thrown, no errors during building and the iterators are of the same type.
Any clues?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Sorry for the late answer, I haven't been accessing the forums lately.
I must admit I had to actually try it in the debugger to understand what is happening
The problem is that your ListOfElements function always returns a copy of the list. So ListOfElements().begin() and ListOfElements().end() are two iterators pointing to different containers.
You have to rememeber that, unlike C#, Java and many others, C++ does not treat variables as references. X x is not a reference to an X, but an object on the stack, just like int x .
You should modify your function's signature to const list & ListOfElements(void) const . Just list & will not work, since your function is const . This will still enable you to copy the container, when you want: list a = obj.ListOfElements() .
A note about style: don't use names starting with an underscore. From MSDN[^]:
Use of two sequential underscore characters ( __ ) at the beginning of an identifier, or a single leading underscore followed by a capital letter, is reserved for C++ implementations in all scopes. You should avoid using one leading underscore followed by a lowercase letter for names with file scope because of possible conflicts with current or future reserved identifiers.
Florin Crisan
|
|
|
|
|
aha!
Thank you VERY much Florin. You have no idea what kind of headache this bug has been causing me. Eventually I gave up on it and finished my homework in C# (I'm an MSc. Student).
But I still don't understand, why a reference has to be returned?
Like here:
Florin Crisan wrote: const list & ListOfElements(void) const
instead of a plain
list ListOfElements(void) const ?
I'm posting this before trying it out to be frank, but I'll be sure to test it out first thing in the morning, its 23:37 here and I've had a horrible day at work then university. :dead tired:
Again Florin, thanks a million!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Mustafa Ismail Mustafa wrote: But I still don't understand, why a reference has to be returned?
Like here:
Florin Crisan wrote:
const list & ListOfElements(void) const
instead of a plain
list ListOfElements(void) const
?
Because you'll return a *copy* of the list every time if you return by value rather than reference. This means that two calls to ListOfElements return different lists, so (as you've already found) their iterators won't be compatible. In addition, returning a new copy every time is expensive in time and memory - you don't want to copy!
Returning by reference is equivalent to what C# does when you return an object from a method - objects are only ever passed around by reference in C# as all objects are heap allocated and garbage collected - that's not true for C++.
|
|
|
|
|
aha!
Stuart, thank you, you've cleared it all up in my mind.
You and Florin have done me a massive favor.
One last question. Since it returns a copy, why are they incompatible? I'd expect them to be compatible, albeit this is scary since you're no longer sure about data correctness. In other words, I can see how this might render the data incorrect (assuming the original is changed but you're reading from the copy) as well as its bad design, but surely the iterator since it is of the same time as the iterator of the original would be compatible.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Well, the thing is, the iterators are incompatible. An iterator is not an index into the container; it's more like a pointer to a specific location. Each iterator is only valid for one container. If you try to compare two iterators pointing to two different containers, it will obviously not work.
Actually, I think it's great that the implementation complains that something's wrong (although the message isn't really obvious). You might have had a very hard to spot bug otherwise.
C# and C++ have a lot of things in common, but still they are quite different. If you are serious about learning it, I can recommend Stroustrup[^]'s The C++ Programming Language[^]. It worked for me
Florin Crisan
|
|
|
|
|
None that I know of. But you can always try boost::algorithm::string::split[^].
See also the example[^].
Boost[^] is a free, peer-reviewed collection of portable C++ source libraries, started by a number of members from the C++ standardisation committee (they've been joined by others in the meantime), aiming to establish "existing practice" and provide reference implementations so that Boost libraries are suitable for eventual standardization. (Yes, the words are from the site ) There is a nice Background Information page[^].
A Windows installer is available here[^].
Florin Crişan
|
|
|
|
|
I wanna create a screen scrapper for the web in WTL. But I'm having a hard time finding a class that will let me access a web url to do it. I know in C# theres WebRequest. and I was wondering how would I go about doing it?
|
|
|
|
|
ATL got some internet-related classes added recently (I forget if it was VC7 or 8). Maybe there's something there for you.
|
|
|
|
|
Hi All,
I have a ActiveX component created using VC++.Net and want to include that in a ATL service created in .Net. But I am not able to add that and use the methods and functions of the ActiveX. Please can someone tell me how to access that ActiveX using Visual Studio 2005.
Thanks
Alpa
|
|
|
|
|
Hi All
I have developed a snapIn.at run time I have an object of class CSnapInItem.
I need to extract the classname of that object that inherit CSnapInItem class at run time.
I have tried CSnapInItem* pItem
typeid(*pItem).name();
but its not wrking....throwing an exception..at run time,...plzz help me..hoe to get the class name at run time.
thanks in advance.
Rashmi
|
|
|
|
|
|
Also make sure your type is a polymorphic type (that is, it has at least one virtual function).
As a rule of thumb, always read the MSDN information (paying extra attention the fine print) when not sure about something.
This article[^] explains quite well how typeid works.
Florin Crişan
|
|
|
|
|
Hi Florin
Thanx a lot for ur response
Rashmi
|
|
|
|
|
Error 1 fatal error C1083: Cannot open include file: 'stdio': No such file or directory
has anyone ever encountered this error while trying to include <stdio> ?
also, it seems to ignore my #include <string> and #include <stddef>
I'm using VS2005 and this is not making sense anymore!
-- modified at 7:25 Friday 23rd November, 2007
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Mustafa Ismail Mustafa wrote: has anyone ever encountered this error while trying to include ?
Never happened (hint: I use #include <stdio.h> )
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.
|
|
|
|
|
You've probably tried #include <stdio>
You should use #include <stdio.h> (like CPallini suggested).
Or, if you want to be standard C++ compliant, you should use #include <cstdio> . Note that this will put every definition definiton in the std namespace.
But if you really want to use C++ (rather than C), you should use <iostream> instead of the C functions.
Still, printf("Value=%d", value) is more convenient than cout << "Value=" << value; . But it's still not type safe. Nor extensible. That's why you should use boost::format[^]
If you are only using C instead of C++: why?
Florin Crişan
|
|
|
|
|
Maybe because it is an alternative
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.
|
|
|
|
|
I created atl com application project and I add atl composite control with connection points support to it. when we build the project a dialog resource appears then I placed combo box on dialog resource. Now how can I add variable to the combo box control and how to customize it.
thanks
Viswanadh
|
|
|
|
|
Hi All
I've developed an MMCSnapin in ATL.I have to implement drag-drop for nodes.
for that I havr to handle MMCN_QUERY_PASTE,MMCN_PASTE,MMCN_COPY events
can anyone tell me how to handle these events...
any suggesstions are highly awaited....
thanks in advance...
Rashmi
|
|
|
|
|
HI,
A::a (EStationID eStnID, VARIANT *pvtConTypes)
{
::CComSafeArray csaConType;
CComVariant varContTypes;
csaConType.CreateOneDim(VT_BSTR,4);
CComBSTR bstrName("Sim_Model1");
CComBSTR bstrName1("Sim_Model2");
CComBSTR bstrName2("Sim_Model3");
CComBSTR bstrName3("Sim_Model4");
csaConType.PutElement((long)0,bstrName.Copy());
csaConType.PutElement(1,bstrName1.Copy());
csaConType.PutElement(2,bstrName2.Copy());
csaConType.PutElement(3,bstrName3.Copy());
*pvtConTypes = csaConType.Detach();
can anyone please tell whether memory leak will occur in this code how to solve it
|
|
|
|