|
From: John P. <jo...@ma...> - 2000-10-31 13:19:06
|
I still get the error:
cannot convert `oAsset' from type `SOME::Object<mriIVisualAsset>' to type
`mriIAsset *'
-Quinticent
"Frank V. Castellucci" wrote:
> You were right the first time, SOME::Object is not a class in the
> hierarchy and once you instantiate it:
>
> --> SOME::Object<mriIVisualAsset>oAsset(assets[0]);
>
> it IS only a SOME::Object/shared_ptr<mriVisualAsset>, but looking at the
> shared_ptr, you should be able to:
>
> --> mriAsset *asset = oAsset;
>
> which should call the coercion operator on boost::shared_ptr. At least
> that's how it behaves (compiles, runs without error) for me in the
> attached emulation test.
>
> "John Palmieri (Quinticent)" wrote:
> >
> > Linux/gcc -
> >
> > Hierarchy:
> >
> > mriIAsset
> > / \
> > / \
> > mriIVisualAsset mriIAudioAsset (There will be more in the future)
> >
> > I think the whole problem is that SOMELib uses some sort of smart pointers
> > that I haven't looked into. Tom is using them in SOME::Object.
> >
> > SOME::Object<T> expands to class SOME::Object : public boost_smart_ptr<T>
> >
> > I haven't looked at the boost stuff and I am not sure if boost_smart_ptr isA
> > T or hasA T. If it is hasA this will have to change. If it cannot be
> > downcast then it needs to be taken out of SOMELib as I am not sure what
> > benefits it gives.
> >
> > -Quinticent
> >
> > "Frank V. Castellucci" wrote:
> >
> > > What is the hierarchy? You may need dynamic_cast<> based on the rules of
> > > usage in 1998(E) C++ standard.
> > > What is the error, and what is the compiler/platform?
> > >
> > > John Palmieri wrote:
> > > >
> > > > I am trying to integrate SOMELib into snaglepuss and am having errors
> > > > with downcasting my objects.
> > > >
> > > > You see I have a hiarchy of interfaces for use with dynamicly loadable
> > > > assets (png, mp3, mpg files). They all get loaded and stuffed into
> > > > chests which are just glorified vectors of type mriIAsset *. Now each
> > > > of the assets can be rendered to the screen, audio device, etc. with a
> > > > call to the render() method. But, each type of asset also has enhanced
> > > > functionality based on their type so my png loader asset would also
> > > > inherit the interface mriIVisualAsset which would in turn inherit the
> > > > mriIAsset interface. The problem I am having is that when I load my
> > > > object I check to see if it is visual, audio. Let's say it is a visual
> > > > asset. I then use this code to construct the object:
> > > >
> > > > SOME::Object<mriIVisualAsset>oAsset(assets[0]);
> > > > //construct our asset
> > > > if(!oAsset.construct()){ ...
> > > >
> > > > this works fine but now I want to add this asset to my chest:
> > > >
> > > > asset = static_cast<mriIAsset *>(oAsset); //error here. I'm guessting
> > > > the template is not truly inheriting
> > > >
> > > > chest->addAsset( chestpos, asset );//I should be able to mix and match
> > > > different assests in my chest
> > > >
> > > > This is an important feature and as much as I know you love the boost
> > > > stuff if it restricts projects from using standard C++ mechanisms when
> > > > working with SOMELib it will have to go.
> > > >
> > > > -Quinticent
> > > >
> > > > _______________________________________________
> > > > somelib-devel mailing list
> > > > som...@li...
> > > > http://lists.sourceforge.net/mailman/listinfo/somelib-devel
> > >
> > > --
> > > Frank V. Castellucci
> > > http://corelinux.sourceforge.net
> > > OOA/OOD/C++ Standards and Guidelines for Linux
> > > http://PythPat.sourceforge.net
> > > Pythons Pattern Package
> > > _______________________________________________
> > > somelib-devel mailing list
> > > som...@li...
> > > http://lists.sourceforge.net/mailman/listinfo/somelib-devel
> >
> > _______________________________________________
> > somelib-devel mailing list
> > som...@li...
> > http://lists.sourceforge.net/mailman/listinfo/somelib-devel
>
> --
> Frank V. Castellucci
> http://corelinux.sourceforge.net
> OOA/OOD/C++ Standards and Guidelines for Linux
> http://PythPat.sourceforge.net
> Pythons Pattern Package
>
> ------------------------------------------------------------------------
>
> #include <iostream>
>
> template <typename T>
> class boostemul
> {
> public:
> boostemul(T *aT)
> :
> theValue(aT)
> {
> }
> operator T*( void ) const
> {
> return theValue;
> }
> private:
> T *theValue;
> };
>
> template <typename U>
> class somObjemu : public boostemul<U>
> {
> public:
> somObjemu( U *aU )
> :
> boostemul<U>( aU )
> {
> }
> };
>
> class mriAsset
> {
> public:
> mriAsset(){}
> virtual void render( void ) = 0;
> };
>
> class mriAudioAsset : public mriAsset
> {
> public:
> mriAudioAsset():mriAsset(){}
> virtual void render( void )
> {
> cout << "In audio render." << endl;
> }
> };
>
> class mriVisualAsset : public mriAsset
> {
> public:
> mriVisualAsset():mriAsset(){}
> virtual void render( void )
> {
> cout << "In visual render." << endl;
> }
> };
>
> int main( void )
> {
> mriVisualAsset anA2;
>
> somObjemu<mriVisualAsset> aObj(&anA2);
>
> mriAsset *pA = aObj;
> pA->render();
> return 0;
> }
|