Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[vc6] LNK1179 "duplicate comdat" workaround

325 views
Skip to first unread message

dave.a...@gmail.com

unread,
May 24, 2006, 7:12:21 PM5/24/06
to
Among other bugs, http://tinyurl.com/moxw8
(http://groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/811cc53a3d36d276/44768de68d91a640)
describes the error shown in the title, and suggests using a static
function member as a workaround. That approach doesn't work when you
really need the instantiation of the object to cause it to be
constructed at startup time, rather than at the point in the code where
the object is used. The following version of the OP's example program
shows how you can turn the static member into a dynamically initialized
reference, which makes the workaround completely transparent and
functionally identical.

---------


// P78.cpp

class Object
{

};

class DB_Operation
: public Object // must have a base class
{

};

template <class Owner, class Element>
class DB_Set
{
static DB_Operation& get_cardinality_selection()
{
static DB_Operation x;
return x;
}
public:
static DB_Operation& _cardinality_selection;

};

template <class Owner, class Element>
DB_Operation& DB_Set<Owner, Element>::_cardinality_selection =
DB_Set<Owner, Element>::get_cardinality_selection();

class PP_Container_Class_Property
{

};

class PP_Component
{

};

class PP_Class
{
public:
DB_Set<PP_Class, PP_Container_Class_Property> _employments;
DB_Set<PP_Class, PP_Component> _components;

};

int main()
{
PP_Class u1;

return &u1._employments._cardinality_selection
== &u1._components._cardinality_selection;
}

0 new messages