Due to the tightening of the VC++ compiler in 2005, I have run into a
compiler error (from code that previously worked in 2003) using a
CComPtr<ITypeLi b> as an element of a std::list, as follows
std::list<CComP tr<ITypeLib> >. I understand the problem, so am looking
for the correct solution to my problem.
On the line that attempts to call push_back, I receive "error C2664:
'std::allocator <_Ty>::construc t' : cannot convert parameter 1 from
'ITypeLib **' to 'ATL::CComPtr<T > *' c:\program files\microsoft visual
studio 8\vc\include\li st 1163"
e.g.
std::list<CComP tr<ITypeLib> > typeLibs;
CComPtr<ITypeLi b> spTypeLib;
... some code the creates an instance of spTypeLib
list.push_back( spTypeLib); // fails here with the C2664 error.
The problem is the push_back function takes a by reference parameter of
type CComPtr<ITypeLi b>, however the CComPtr class overrides operator&,
returning a value of type ITypeLib**.
I want to use the CComPtr, for the benefits of the RAII pattern, and it
simplifies my production code significantly in this set of routines.
My question is "What is the correct way to handle this situation, and
avoid the overloaded operator& issue?"
Cheers,
Stuart 9 4642
Stuart Carnie wrote: Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLi b> as an element of a std::list, as follows std::list<CComP tr<ITypeLib> >. I understand the problem, so am looking for the correct solution to my problem.
On the line that attempts to call push_back, I receive "error C2664: 'std::allocator <_Ty>::construc t' : cannot convert parameter 1 from 'ITypeLib **' to 'ATL::CComPtr<T > *' c:\program files\microsoft visual studio 8\vc\include\li st 1163"
e.g.
std::list<CComP tr<ITypeLib> > typeLibs;
CComPtr<ITypeLi b> spTypeLib;
.. some code the creates an instance of spTypeLib
list.push_back( spTypeLib); // fails here with the C2664 error.
The problem is the push_back function takes a by reference parameter of type CComPtr<ITypeLi b>, however the CComPtr class overrides operator&, returning a value of type ITypeLib**.
I want to use the CComPtr, for the benefits of the RAII pattern, and it simplifies my production code significantly in this set of routines.
My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
Cheers,
Stuart
Just want to add, that
typeLibs.push_b ack(reinterpret _cast<CComPtr<I TypeLib> >(spTypeLib)) ;
does not work, receive the following (suspicious) error
"error C2440: 'reinterpret_ca st' : cannot convert from
'ATL::CComPtr<T >' to 'ATL::CComPtr<T >'
d:\sourcecode\s lx_scorpion\pro jects\oledb_pro vider\commonsys \cdynamicobject .cpp
535"
Notice it says cannot convert from same type.
"Stuart Carnie" <st***********@ nospam.nospam> wrote in message
news:%2******** *********@TK2MS FTNGP10.phx.gbl ... Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLi b> as an element of a std::list, as follows std::list<CComP tr<ITypeLib> >. I understand the problem, so am looking for the correct solution to my problem.
On the line that attempts to call push_back, I receive "error C2664: 'std::allocator <_Ty>::construc t' : cannot convert parameter 1 from 'ITypeLib **' to 'ATL::CComPtr<T > *' c:\program files\microsoft visual studio 8\vc\include\li st 1163"
e.g.
std::list<CComP tr<ITypeLib> > typeLibs;
CComPtr<ITypeLi b> spTypeLib;
.. some code the creates an instance of spTypeLib
list.push_back( spTypeLib); // fails here with the C2664 error.
The problem is the push_back function takes a by reference parameter of type CComPtr<ITypeLi b>, however the CComPtr class overrides operator&, returning a value of type ITypeLib**.
I want to use the CComPtr, for the benefits of the RAII pattern, and it simplifies my production code significantly in this set of routines.
My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
The best solution is to avoid classes that overload operator & - they're
inherently incompatible with the standard library containers (despite the
fact that some combinations may actually work).
The only general soution that I know of is to wrap the type with another
type that forwards the entire public interface except for operator &. With
a smartpoint type, that'll no doubt cause some other problems somewhere
since it'll probably add a conversion to various sequences, which will in
turn make some implicit conversions no longer work (since they'll now
require two user defined conversions instead of one).
ATL actually supplies a wrapper for just this purpose: CAdapt<T>
-cd
Carl Daniel [VC++ MVP] wrote: "Stuart Carnie" <st***********@ nospam.nospam> wrote in message news:%2******** *********@TK2MS FTNGP10.phx.gbl ... Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLi b> as an element of a std::list, as follows std::list<CComP tr<ITypeLib> >. I understand the problem, so am looking for the correct solution to my problem.
On the line that attempts to call push_back, I receive "error C2664: 'std::allocator <_Ty>::construc t' : cannot convert parameter 1 from 'ITypeLib **' to 'ATL::CComPtr<T > *' c:\program files\microsoft visual studio 8\vc\include\li st 1163"
e.g.
std::list<CComP tr<ITypeLib> > typeLibs;
CComPtr<ITypeLi b> spTypeLib;
.. some code the creates an instance of spTypeLib
list.push_back( spTypeLib); // fails here with the C2664 error.
The problem is the push_back function takes a by reference parameter of type CComPtr<ITypeLi b>, however the CComPtr class overrides operator&, returning a value of type ITypeLib**.
I want to use the CComPtr, for the benefits of the RAII pattern, and it simplifies my production code significantly in this set of routines.
My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
The best solution is to avoid classes that overload operator & - they're inherently incompatible with the standard library containers (despite the fact that some combinations may actually work).
The only general soution that I know of is to wrap the type with another type that forwards the entire public interface except for operator &. With a smartpoint type, that'll no doubt cause some other problems somewhere since it'll probably add a conversion to various sequences, which will in turn make some implicit conversions no longer work (since they'll now require two user defined conversions instead of one).
ATL actually supplies a wrapper for just this purpose: CAdapt<T>
-cd
Thanks for that..
Out of interest, I had to see what had changed, and it turns out to be
fairly simple:
In <list>, this method has changed between 2003 and 2005
_Nodeptr _Buynode(_Nodep tr _Next,
_Nodeptr _Prev, const _Ty& _Val)
{ // allocate a node and set links and value
// surrounding code removed for clarity
// this line causes the compilation issue.
// 2003 used the new operator to construct the object
this->_Alval.constru ct(&_Myval(_Pno de), _Val);
// code removed for clarity
}
Carl Daniel [VC++ MVP] wrote: "Stuart Carnie" <st***********@ nospam.nospam> wrote in message news:%2******** *********@TK2MS FTNGP10.phx.gbl ... Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLi b> as an element of a std::list, as follows std::list<CComP tr<ITypeLib> >. I understand the problem, so am looking for the correct solution to my problem.
On the line that attempts to call push_back, I receive "error C2664: 'std::allocator <_Ty>::construc t' : cannot convert parameter 1 from 'ITypeLib **' to 'ATL::CComPtr<T > *' c:\program files\microsoft visual studio 8\vc\include\li st 1163"
e.g.
std::list<CComP tr<ITypeLib> > typeLibs;
CComPtr<ITypeLi b> spTypeLib;
.. some code the creates an instance of spTypeLib
list.push_back( spTypeLib); // fails here with the C2664 error.
The problem is the push_back function takes a by reference parameter of type CComPtr<ITypeLi b>, however the CComPtr class overrides operator&, returning a value of type ITypeLib**.
I want to use the CComPtr, for the benefits of the RAII pattern, and it simplifies my production code significantly in this set of routines.
My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
The best solution is to avoid classes that overload operator & - they're inherently incompatible with the standard library containers (despite the fact that some combinations may actually work).
The only general soution that I know of is to wrap the type with another type that forwards the entire public interface except for operator &. With a smartpoint type, that'll no doubt cause some other problems somewhere since it'll probably add a conversion to various sequences, which will in turn make some implicit conversions no longer work (since they'll now require two user defined conversions instead of one).
ATL actually supplies a wrapper for just this purpose: CAdapt<T>
-cd
Thanks for that..
Out of interest, I had to see what had changed, and it turns out to be
fairly simple:
In <list>, this method has changed between 2003 and 2005
_Nodeptr _Buynode(_Nodep tr _Next,
_Nodeptr _Prev, const _Ty& _Val)
{ // allocate a node and set links and value
// surrounding code removed for clarity
// this line causes the compilation issue.
// 2003 used the new operator to construct the object
this->_Alval.constru ct(&_Myval(_Pno de), _Val);
// code removed for clarity
}
Carl Daniel [VC++ MVP] wrote: "Stuart Carnie" <st***********@ nospam.nospam> wrote in message news:%2******** *********@TK2MS FTNGP10.phx.gbl ... Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLi b> as an element of a std::list, as follows std::list<CComP tr<ITypeLib> >. I understand the problem, so am looking for the correct solution to my problem.
On the line that attempts to call push_back, I receive "error C2664: 'std::allocator <_Ty>::construc t' : cannot convert parameter 1 from 'ITypeLib **' to 'ATL::CComPtr<T > *' c:\program files\microsoft visual studio 8\vc\include\li st 1163"
e.g.
std::list<CComP tr<ITypeLib> > typeLibs;
CComPtr<ITypeLi b> spTypeLib;
.. some code the creates an instance of spTypeLib
list.push_back( spTypeLib); // fails here with the C2664 error.
The problem is the push_back function takes a by reference parameter of type CComPtr<ITypeLi b>, however the CComPtr class overrides operator&, returning a value of type ITypeLib**.
I want to use the CComPtr, for the benefits of the RAII pattern, and it simplifies my production code significantly in this set of routines.
My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
The best solution is to avoid classes that overload operator & - they're inherently incompatible with the standard library containers (despite the fact that some combinations may actually work).
The only general soution that I know of is to wrap the type with another type that forwards the entire public interface except for operator &. With a smartpoint type, that'll no doubt cause some other problems somewhere since it'll probably add a conversion to various sequences, which will in turn make some implicit conversions no longer work (since they'll now require two user defined conversions instead of one).
ATL actually supplies a wrapper for just this purpose: CAdapt<T>
-cd
Thanks for that..
Out of interest, I had to see what had changed, and it turns out to be
fairly simple:
In <list>, this method has changed between 2003 and 2005
_Nodeptr _Buynode(_Nodep tr _Next,
_Nodeptr _Prev, const _Ty& _Val)
{ // allocate a node and set links and value
// surrounding code removed for clarity
// this line causes the compilation issue.
// 2003 used the new operator to construct the object
this->_Alval.constru ct(&_Myval(_Pno de), _Val);
// code removed for clarity
}
Carl Daniel [VC++ MVP] wrote: "Stuart Carnie" <st***********@ nospam.nospam> wrote in message news:%2******** *********@TK2MS FTNGP10.phx.gbl ... Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLi b> as an element of a std::list, as follows std::list<CComP tr<ITypeLib> >. I understand the problem, so am looking for the correct solution to my problem.
On the line that attempts to call push_back, I receive "error C2664: 'std::allocator <_Ty>::construc t' : cannot convert parameter 1 from 'ITypeLib **' to 'ATL::CComPtr<T > *' c:\program files\microsoft visual studio 8\vc\include\li st 1163"
e.g.
std::list<CComP tr<ITypeLib> > typeLibs;
CComPtr<ITypeLi b> spTypeLib;
.. some code the creates an instance of spTypeLib
list.push_back( spTypeLib); // fails here with the C2664 error.
The problem is the push_back function takes a by reference parameter of type CComPtr<ITypeLi b>, however the CComPtr class overrides operator&, returning a value of type ITypeLib**.
I want to use the CComPtr, for the benefits of the RAII pattern, and it simplifies my production code significantly in this set of routines.
My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
The best solution is to avoid classes that overload operator & - they're inherently incompatible with the standard library containers (despite the fact that some combinations may actually work).
The only general soution that I know of is to wrap the type with another type that forwards the entire public interface except for operator &. With a smartpoint type, that'll no doubt cause some other problems somewhere since it'll probably add a conversion to various sequences, which will in turn make some implicit conversions no longer work (since they'll now require two user defined conversions instead of one).
ATL actually supplies a wrapper for just this purpose: CAdapt<T>
-cd
Thanks for that..
Out of interest, I had to see what had changed, and it turns out to be
fairly simple:
In <list>, this method has changed between 2003 and 2005
_Nodeptr _Buynode(_Nodep tr _Next,
_Nodeptr _Prev, const _Ty& _Val)
{ // allocate a node and set links and value
// surrounding code removed for clarity
// this line causes the compilation issue.
// 2003 used the new operator to construct the object
this->_Alval.constru ct(&_Myval(_Pno de), _Val);
// code removed for clarity
}
> My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
Use:
std::list<CComP tr<CAdapt <ITypeLib> > > typeLibs;
Brian
"Brian Muth" <bm***@mvps.org > wrote in message
news:uj******** ********@TK2MSF TNGP11.phx.gbl. .. My question is "What is the correct way to handle this situation, and avoid the overloaded operator& issue?"
Use:
std::list<CComP tr<CAdapt <ITypeLib> > > typeLibs;
Make that
std::list<CAdap t<CComPtr<IType Lib> > > typeLibs;
-cd Make that
std::list<CAdap t<CComPtr<IType Lib> > > typeLibs;
-cd
(embarrassed look)
Thanks, Carl.
Brian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mr A |
last post by:
Hi!
I've been thinking about passing parameteras using references instead
of pointers in order to emphasize that the parameter must be an
object.
Exemple:
void func(Objec& object); //object must be an object
instead of
|
by: Radde |
last post by:
HI all,
Whats the difference b/w pass by ref and pass by pointer in C++ when
ur passing objects as args..
Cheers..
|
by: Benny |
last post by:
I need to pass a reference of a managed object to a function (bar). I
believe the syntax is correct. When I build the project, a message box with
the title "Microsoft (R) C/C++ Optimizing Compiler" displays indicating that
a GPF has occurred.
Is this a compiler bug?
Sample Code:
class foo
{
|
by: Abhi |
last post by:
I wrote a function foo(int arr) and its prototype
is declared as foo(int arr); I modify the values of the array in the
function and the values are getting modified in the main array which
is passed also. I understand that this way of passing the array is by
value and if the prototype is declared as foo(int *), it is by
reference in which case...
|
by: Jess |
last post by:
Hello,
I learned that when I work with templates in C++, I should have
functions that pass arguments by reference because the type of object
is not known. Does it mean that if I have a function that is template
function, then it's argument should be a reference type, such as the
following?
template<class T>
void f(T& t){...}
| |
by: lisp9000 |
last post by:
I've read that C allows two ways to pass information between
functions:
o Pass by Value
o Pass by Reference
I was talking to some C programmers and they told me there is no such
thing as pass by reference in C since you are just passing an address
(or a pointer value address I guess?). So I was wondering is this
correct?
|
by: Bryan Parkoff |
last post by:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope. The global
variables and global functions are hidden to prevent from accessing by the
programmers. All global functions share global variables....
|
by: raylopez99 |
last post by:
I'm posting this fragment from another thread to frame the issue
clearer.
How to pass an object to a function/method call in C# that will
guarantee not to change the object?* In C++, as seen below, you can
use the 'const' keyword in the function / method declaration. But how
to do this in C#?
*for example: "void Foo() const;"
|
by: raylopez99 |
last post by:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms.
Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed!...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |