|
Robert Edward Caldecott wrote:
You don't think smart pointers are useful?
I think, somebody who puts pointers or smart pointers into a std container has not understood one basic principle of STL, that is, 'value semantics'.
What a shame. Other than the fact that both STL and Boost are incredibly powerful, I need to write code for Windows AND Linux, and without these libraries, this would be difficuly to achieve.
It's ok if it works for you. IMO, it's not really elegant that one has to write
v.push_back(boost::shared_ptr<CFoo>(new CFoo));
to insert an element.
|
|
|
|
|
CP Visitor wrote:
It's ok if it works for you. IMO, it's not really elegant that one has to write
Why not? You could always use typedef:
typedef boost::shared_ptr<CFoo> foo_sp;
...
v.push_back(foo_sp(new CFoo));
Elegant enough IMO, though people seem to either love or hate typedef. Using smart pointers in containers is very useful, and from experience, it has meant more time concentrating on the job at hand instead of tracking down memory leaks. I did use the ATL7 CAutoPtr class (and associated CAtlArray/CAtlList) but that's no help for writing portable code plus I prefer using STL iterators over MFC's 'POSITION' scheme. Shrug.
Whatever works I guess. But the more I use STL/Boost, the more I wonder why I went so long without it!
|
|
|
|
|
Boost.MPL[^] is an impressive achievement and a mind-opener for those venturing into the world of C++ metaprogramming. I wonder, however, how much real use metaprogramming gets in the C++ community.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
|
Is Boost a full STL implementation? If so, won't some of the classes clash with VC++'s STL classes? Or are the Boost classes in a different namespace?
|
|
|
|
|
Nishant Sivakumar wrote:
Is Boost a full STL implementation?
No - it's not an STL implementation at all...apart from some of the things that are added at TR1 (like regex, smart pointers, function and some other stuff) and are so are not yet in any STL that you'll have access to). Really, if you consider Boost as a sandpit for libraries that are or could be potential additions to the Standard C++ library, you're not far wrong.
Also - Boost classes are all in the boost namespace or a child namespace of boost.
|
|
|
|
|
|
Hello all.
I'm writing WMI Instance/Method provider. Working in VS.NET 2003. ClassWiz generates some code for WMI Instance Provider, using IWbemInstProviderImpl class. I haven't managed to find any documentation about the wizard usage or about the class and classes discribed in the same header file.
Please, let me know, if someone knows where I can get some information about the stuff.
Thanks in advance.
Just a student!
|
|
|
|
|
I am currently working on handling ATL COM events in WIN32 exe (on winCE platform using eVC++). I am able to raise an event in COM component but not able to handle it in WIN32 exe.
I have tried different ways to implement this functionality but the results are same. If I port the code in VC++ it works fine.
My work has halted due to this problem. Please let me know the solution to this problem.
Thanks in advance.
|
|
|
|
|
Hello, All!
I need to place a background image to my CListViewCtrl. How to do it??? I used WM_ERASEBKGND handler, but list-view' items cover my image...
(Report, List view)
|
|
|
|
|
|
I am trying to host an ActiveX control in a WTL Dialog app, very similar to what the example in the article "WTL for MFC Programmers, Part VI". I think the example given by Michael Dunn will be a great help to me, except that it does not complile in Visual Studio .NET 2003. There must have been changes to ATL or WTL that make the code not compile? Can anyone help me get it to build?
|
|
|
|
|
Here are the errors I am getting when I try to build:
Compiling...
maindlg.cpp
d:\samples\WTL4MFC6_demo\IEHost\maindlg.h(112) : error C2955: 'ATL::IDispEventSimpleImpl' : use of class template requires template argument list
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(4122) : see declaration of 'ATL::IDispEventSimpleImpl'
d:\samples\WTL4MFC6_demo\IEHost\maindlg.h(112) : error C2440: 'static_cast' : cannot convert from 'CMainDlg::_ComMapClass *' to 'ATL::IDispEventSimpleImpl *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\samples\WTL4MFC6_demo\IEHost\maindlg.h(112) : error C2440: 'initializing' : cannot convert from 'ATL::_ATL_CREATORARGFUNC (__stdcall *)' to 'DWORD_PTR'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
IEHost.cpp
d:\samples\WTL4MFC6_demo\IEHost\maindlg.h(112) : error C2955: 'ATL::IDispEventSimpleImpl' : use of class template requires template argument list
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(4122) : see declaration of 'ATL::IDispEventSimpleImpl'
d:\samples\WTL4MFC6_demo\IEHost\maindlg.h(112) : error C2440: 'static_cast' : cannot convert from 'CMainDlg::_ComMapClass *' to 'ATL::IDispEventSimpleImpl *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\samples\WTL4MFC6_demo\IEHost\maindlg.h(112) : error C2440: 'initializing' : cannot convert from 'ATL::_ATL_CREATORARGFUNC (__stdcall *)' to 'DWORD_PTR'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Generating Code...
IEHost - 6 error(s), 0 warning(s)
|
|
|
|
|
Yeah, I did things the hard way in that example - there's no need to manually build the SINK_MAP macros since ClassWizard (in VC6 at least) can do it for you. I haven't looked at VC7 enough to know where the equivalent feature is but I would assume it's still in there.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
hello,
i've created a std::list of objects, and it works well, but i'd like to support additional functionality for the list, such as writing certain aspects of the objects to stdout/cout (or dumping them using TRACE macros), matching certain aspects of objects (i.e., several different "match" functions), populating a list box with objects' names, etc. i've tried 2 approaches:
1. wrap the std::list in a class that handles these functions by using the list's iterators. this is inelegant, so i switched to:
2. subclass my std::list<myobject>, and add the functions i need to the new class. from what i've read on the web, subclassing std::list isn't a good idea, due to the virtual destructor problem.
my guess is that i should be using functions that operate on this list, but creating functions instead of list methods seems to violate the whole point of using c++. i'd appreciate any advice, since this is my first project using the stl, and i'm still waiting for my stl book to arrive in the mail....
ed
|
|
|
|
|
If you don't add any new data in your derived class, you should be OK in most cases (because your derived destructor won't actually need to do anything more than the std::lsit destructor).
OTOH - ehh wrote: violate the whole point of using c++ - well, C++ is a multi-paradigm language, so using separate free functions doesn't really violate any point of C++....
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Hi All, I have a program which uses the IE engine to display HTML documents (using ATL) in my program's window. I'm trying to figure out how to make the COPY work, when some of the highlighted display is right-clicked. The program isn't creating the edit menu which appears when it is right-clicked, so I assume IE is doing that. The COPY appears in the menu, but clicking on it does not copy the text to the clipboard (at least, doing paste after that does not paste what I just tried to copy). If I display the same html doc in Internet Explorer, then the copy works fine. I've tried adding this code: m_spOleCmdTarg->Exec(NULL,OLECMDID_COPY,OLECMDEXECOPT_DONTPROMPTUSER,NULL,NULL); which does get executed when the user clicks on Copy in the System Menu. But still, the paste does not paste what I just tried to copy. Does anyone have any idea what I might be missing here? Any ideas are greatly appreciated. Thanks, Melena
|
|
|
|
|
I did this in one of my apps:
pWB2->ExecWB ( OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL ); and it works without a hitch. I'm using a different interface than you, however.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Thanks Mike. So you didn't have to enable anything to make the copy work? I've seen things like UIEnable function calls, so I'm wondering if that's what I'm missing. Also, had you created your own menu which is run when the user right-clicks in the browser, or was it just using the IE engine right-click menu? I'm wondering how you knew when to execute the pWB2->ExecWB... Thanks again, Melena
|
|
|
|
|
I've figured this problem out. Was using CoInitialize() instead of OleInitialize(). The OleInitialize() makes the clipboard available, once I started using that, the copy worked fine.
|
|
|
|
|
|
If I have an STL container that contains objects, then I can compare them easily - for example:
class CMyClass
{
int m_n;
CMyClass(int n) : m_n(n) { }
bool operator==(const CMyClass& o) const
{
}
};
...
vector<CMyClass> v1;
vector<CMyClass> v2;
v1.push_back(CMyClass(1234));
v2.push_back(CMyClass(1234));
if (v1 == v2)
However, I often use containers of pointers, and when I do, comparing two containers doesn't call the objects operator== function. For example:
class CMyClass
{
int m_n;
CMyClass(int n) : m_n(n) { }
bool operator==(const CMyClass& o) const
{
}
};
...
vector<CMyClass*> v1;
vector<CMyClass*> v2;
v1.push_back(new CMyClass(1234));
v2.push_back(new CMyClass(1234));
if (v1 == v2)
My question is - are there any operators I can overload to make the comparison work for containers of pointers, or do I need to hand-roll my own comparison function? I hope this makes sense!
The Rob Blog
|
|
|
|
|
OK, after some experimenting I realised that std::equal can be passed a function object, so I now have something like this:
template <class T>
class EqualT
{
public:
inline bool operator()(const T* t1, const T* t2) { return *t1 == *t2; }
};
...
vector<CMyClass*> v1;
vector<CMyClass*> v2;
...
if (equal(v1.begin(), v1.end(), v2.begin(), EqualT<CMyClass>()))
Using a function object template means I can compare containers containing other pointer type - the EqualT operator() handles the de-referencing. Nice.
The Rob Blog
|
|
|
|
|
I meant:
struct EqualT
{
template <class T>
inline bool operator()(const T* t1, const T* t2) const { return *t1 == *t2; }
};
...
vector<CMyClass*> v1;
vector<CMyClass*> v2;
...
if (equal(v1.begin(), v1.end(), v2.begin(), EqualT()))
|
|
|
|
|