mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:56:43 +00:00 
			
		
		
		
	Use dynamic_cast to get the LiveCellRef
This commit is contained in:
		
							parent
							
								
									48c07fbd98
								
							
						
					
					
						commit
						86f2cd5848
					
				
					 2 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
					@ -28,6 +28,8 @@ namespace MWWorld
 | 
				
			||||||
        LiveCellRefBase(std::string type, const ESM::CellRef &cref=ESM::CellRef())
 | 
					        LiveCellRefBase(std::string type, const ESM::CellRef &cref=ESM::CellRef())
 | 
				
			||||||
          : mTypeName(type), mRef(cref), mData(mRef)
 | 
					          : mTypeName(type), mRef(cref), mData(mRef)
 | 
				
			||||||
        { }
 | 
					        { }
 | 
				
			||||||
 | 
					        /* Need this for the class to be recognized as polymorphic */
 | 
				
			||||||
 | 
					        virtual ~LiveCellRefBase() { }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// A reference to one object (of any type) in a cell.
 | 
					    /// A reference to one object (of any type) in a cell.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,8 +46,8 @@ namespace MWWorld
 | 
				
			||||||
            template<typename T>
 | 
					            template<typename T>
 | 
				
			||||||
            MWWorld::LiveCellRef<T> *get() const
 | 
					            MWWorld::LiveCellRef<T> *get() const
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if(mRef && mRef->mTypeName == typeid(T).name())
 | 
					                MWWorld::LiveCellRef<T> *ref = dynamic_cast<MWWorld::LiveCellRef<T>*>(mRef);
 | 
				
			||||||
                    return static_cast<MWWorld::LiveCellRef<T>*>(mRef);
 | 
					                if(ref) return ref;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                std::stringstream str;
 | 
					                std::stringstream str;
 | 
				
			||||||
                str<< "Bad LiveCellRef cast to "<<typeid(T).name()<<" from ";
 | 
					                str<< "Bad LiveCellRef cast to "<<typeid(T).name()<<" from ";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue