Hello,
I'm having problems with heavy use of templates, I'm using an adobe sdk for indesign (you can see here: http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=4126), I'm trying to reproduce it but I have mixed results, in some case it works, in others not.
These are the classes I built in order to reproduce the problem:
class IFooBase
{
public:
virtual void AddRef() = 0;
virtual void Release() = 0;
virtual IFooBase* QueryInterface(int32 id) const = 0;
};
class IFoo : public IFooBase
{
public:
virtual int32 GetBar() = 0;
};
class IFooSession: public IFooBase
{
public:
virtual int32 GetSessionID() = 0;
};
template <class IFace>
class IntfPtr
{
public:
explicit IntfPtr(IFace* p)
: fFace(p) {
(void) static_cast<const IFooBase*>(p);
}
IntfPtr(const IFooBase* p, int32 id)
: fFace(QueryInterface_(p, id)) {}
IFace* forget() {
IFace* result = fFace;
fFace = 0;
return result;
}
IFace * operator ->() const { return fFace; }
protected:
static IFace* QueryInterface_(const IFooBase* p, int32 id)
{ return p ? static_cast<IFace*>(p->QueryInterface(id)) : nil; }
protected:
IFace* fFace;
};
template <class IFace>
class FooUtils
{
public:
inline FooUtils() : fPtr(nil)
{
IntfPtr<IFace> utilsIntf(fSession, 0);
fPtr = utilsIntf.forget();
};
inline IFace* operator ->() const { return static_cast<IFace*>(fPtr); }
protected:
IFooBase* fPtr;
IFooSession* fSession;
};
template <class Interface>
class CFooBase : public Interface
{
public:
inline CFooBase(IFooBase* base)
: fPtr(base)
{}
inline void AddRef() {}
inline void Release() {}
protected:
IFooBase* fPtr;
};
class CFoo : CFooBase<IFoo>
{
public:
CFoo(IFooBase* base) : CFooBase<IFoo>(base) {}
int32 GetBar() { return 32; }
};
class CTest
{
public:
CTest() {
FooUtils<IFoo> foo;
foo->
}
};
At first it gave me the wrong results (I've taken the screenshot but I was unable to include it in this topic, anyway the method list was only the constructor of FooUtils and the protected member fPtr) and later, when I tried to expand the sample (adding IFooSession for example), it gave me right results (all the methods of IFoo and IFooBase).
However it is not working with the AdobeSDK that exibits similar classes (I don't know if the problem depends of the use of precompiled headers, use of inline methods or on the fact that all the interfaces and helper classes are on their own include file).
I've to say that it is working with build 1446.
Kindest Regards,
- mn