Click here to Skip to main content
15,899,020 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: XP Themes not woking in an ActiveX control in IE Pin
Michael Dunn20-Jan-04 12:57
sitebuilderMichael Dunn20-Jan-04 12:57 
GeneralRe: XP Themes not woking in an ActiveX control in IE Pin
Jason De Arte20-Jan-04 15:34
Jason De Arte20-Jan-04 15:34 
GeneralRe: XP Themes not woking in an ActiveX control in IE Pin
Michael Dunn21-Jan-04 13:03
sitebuilderMichael Dunn21-Jan-04 13:03 
GeneralRe: XP Themes not woking in an ActiveX control in IE Pin
Jason De Arte21-Jan-04 14:37
Jason De Arte21-Jan-04 14:37 
Generalputting template objects in a container Pin
Joo Andras19-Jan-04 3:33
Joo Andras19-Jan-04 3:33 
GeneralRe: putting template objects in a container Pin
Joaquín M López Muñoz19-Jan-04 6:15
Joaquín M López Muñoz19-Jan-04 6:15 
GeneralRe: putting template objects in a container Pin
Joo Andras19-Jan-04 21:14
Joo Andras19-Jan-04 21:14 
GeneralRe: putting template objects in a container Pin
Lim Bio Liong20-Jan-04 5:02
Lim Bio Liong20-Jan-04 5:02 
Hello Joo,

I think Joaquin's solution is really cool. But I think we may have missed your earlier concern : how to obtain the actual derived class object contained within the vector.

If we used a vector of pointers to X_base objects, we will obtain only pointers to X_base objects when we iterate through the vector.

We need to be able to determine at runtime the following information :

1. What is the X_base-derived-template-class of each vector item.

2. What is the type that is actually used to instantiate the X_base-derived template class (in your earlier example, this is actually 'int' or 'double').

Inspired by Joaquin, I went on to refine his example source codes and produced the following :

#include <vector>
#include <iostream>
#include <typeinfo.h>

using namespace std;

class X_base
{
public :
X_base()
{
}

virtual operator const type_info&() = 0;
};





template <class T>
class X: public X_base
{
public :
typedef T MyType;

X(MyType t) :
m_t(t),
m_ti(typeid(t))
{
}

virtual operator const type_info&()
{
return m_ti;
}

MyType& GetValue()
{
return m_t;
}

protected :

MyType m_t;
const type_info& m_ti;
};

typedef X<int> X_int;
typedef X<double> X_double;
typedef std::vector<X_base*> X_base_vector;

int _tmain(int argc, _TCHAR* argv[])
{
X_int* pxi = new X_int(5);
X_double* pxd = new X_double(0.85);
X_base_vector x_base_vector;
X_base_vector::iterator theIterator;
const type_info& ti_int = typeid(int);
const type_info& ti_double = typeid(double);
int i = 0;

cout << ti_int.name() << endl;
cout << ti_double.name() << endl;

x_base_vector.push_back(pxi);
x_base_vector.push_back(pxd);

for (theIterator = x_base_vector.begin(); theIterator != x_base_vector.end(); theIterator++)
{
X_base* px = *theIterator;

if (ti_int == (const type_info&)(*px))
{
X_int* pxi = dynamic_cast<X_int*>(px);

cout << "px == X<int>" << endl;
cout << "Value : " << pxi -> GetValue() << endl;
}

if (ti_double == (const type_info&)(*px))
{
X_double* pxd = dynamic_cast<X_double*>(px);

cout << "px == X<double>" << endl;
cout << "Value : " << pxd -> GetValue() << endl;
}

cout << ((const type_info&)(*px)).name() << endl;
}

return 0;
}

Essentially, I used Run-Time-Type-Information (RTTI) to help determine the class (X_base-derived) of each vector item as well as to determine the type that is actually used to instantiate the X_base-derived template class.

Hope the above code will be helpful to you and Joaquin.

Thanks,
Bio.





GeneralRe: putting template objects in a container Pin
Jörgen Sigvardsson19-Jan-04 12:15
Jörgen Sigvardsson19-Jan-04 12:15 
Generaldifferent template objects into a container Pin
Joo Andras19-Jan-04 3:27
Joo Andras19-Jan-04 3:27 
QuestionHow to load a MFC dll to a WTL project? Pin
freehawk18-Jan-04 15:21
freehawk18-Jan-04 15:21 
AnswerRe: How to load a MFC dll to a WTL project? Pin
Michael Dunn18-Jan-04 16:41
sitebuilderMichael Dunn18-Jan-04 16:41 
GeneralRe: How to load a MFC dll to a WTL project? Pin
freehawk18-Jan-04 16:53
freehawk18-Jan-04 16:53 
GeneralRe: How to load a MFC dll to a WTL project? Pin
Michael Dunn18-Jan-04 16:58
sitebuilderMichael Dunn18-Jan-04 16:58 
GeneralRe: How to load a MFC dll to a WTL project? Pin
freehawk18-Jan-04 17:18
freehawk18-Jan-04 17:18 
GeneralRe: How to load a MFC dll to a WTL project? Pin
Michael Dunn18-Jan-04 19:38
sitebuilderMichael Dunn18-Jan-04 19:38 
GeneralRe: How to load a MFC dll to a WTL project? Pin
freehawk18-Jan-04 19:48
freehawk18-Jan-04 19:48 
GeneralRe: How to load a MFC dll to a WTL project? Pin
Jörgen Sigvardsson19-Jan-04 12:10
Jörgen Sigvardsson19-Jan-04 12:10 
GeneralRe: How to load a MFC dll to a WTL project? Pin
freehawk19-Jan-04 13:34
freehawk19-Jan-04 13:34 
Generalmatching MFC and WTL Pin
lobanovski18-Jan-04 12:37
lobanovski18-Jan-04 12:37 
GeneralRe: matching MFC and WTL Pin
Jörgen Sigvardsson18-Jan-04 13:02
Jörgen Sigvardsson18-Jan-04 13:02 
GeneralSizing an ActiveX control?! Pin
mikewithersone17-Jan-04 2:34
mikewithersone17-Jan-04 2:34 
GeneralRe: Sizing an ActiveX control?! Pin
Jason De Arte19-Jan-04 19:23
Jason De Arte19-Jan-04 19:23 
GeneralactiveX property read only at runtime Pin
Hesham Amin16-Jan-04 6:24
Hesham Amin16-Jan-04 6:24 
GeneralATL object in MFC project Pin
NotBear15-Jan-04 13:21
NotBear15-Jan-04 13:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.