B
Bob Altman
I have a class that is exported from a DLL. This class includes a private
std::vector containing pointers to instances of the class, like this:
class MYCLASS_API MyClass {
private:
vector<MyClass*> m_list;
}
When I compile I get the dreaded Warning C4251: ... needs to have
dll-interface to be used by clients of class...
If m_list was a vector of standard types (such as int) then the solution
would be to modify the code like this (stolen from
http://support.microsoft.com/kb/q168958/):
#ifdef EXP_STL
# define DECLSPECIFIER __declspec(dllexport)
# define EXPIMP_TEMPLATE
#else
# define DECLSPECIFIER __declspec(dllimport)
# define EXPIMP_TEMPLATE extern
#endif
// Instantiate vector<int>
EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<int>;
class MYCLASS_API MyClass {
private:
// Note: Changed from preceding example
vector<int> m_list;
}
My problem is that m_list is a vector of MyClass*, and I don't know to
forward-reference it in the vector instantiation. In other words:
#ifdef EXP_STL
# define DECLSPECIFIER __declspec(dllexport)
# define EXPIMP_TEMPLATE
#else
# define DECLSPECIFIER __declspec(dllimport)
# define EXPIMP_TEMPLATE extern
#endif
// This doesn't compile!
EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<MyClass*>;
class MYCLASS_API MyClass {
private:
vector<MyClass*> m_list;
}
Help!
TIA - Bob
std::vector containing pointers to instances of the class, like this:
class MYCLASS_API MyClass {
private:
vector<MyClass*> m_list;
}
When I compile I get the dreaded Warning C4251: ... needs to have
dll-interface to be used by clients of class...
If m_list was a vector of standard types (such as int) then the solution
would be to modify the code like this (stolen from
http://support.microsoft.com/kb/q168958/):
#ifdef EXP_STL
# define DECLSPECIFIER __declspec(dllexport)
# define EXPIMP_TEMPLATE
#else
# define DECLSPECIFIER __declspec(dllimport)
# define EXPIMP_TEMPLATE extern
#endif
// Instantiate vector<int>
EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<int>;
class MYCLASS_API MyClass {
private:
// Note: Changed from preceding example
vector<int> m_list;
}
My problem is that m_list is a vector of MyClass*, and I don't know to
forward-reference it in the vector instantiation. In other words:
#ifdef EXP_STL
# define DECLSPECIFIER __declspec(dllexport)
# define EXPIMP_TEMPLATE
#else
# define DECLSPECIFIER __declspec(dllimport)
# define EXPIMP_TEMPLATE extern
#endif
// This doesn't compile!
EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<MyClass*>;
class MYCLASS_API MyClass {
private:
vector<MyClass*> m_list;
}
Help!
TIA - Bob