Hey.
I'm running into a problem with a class that uses template metaprogramming. I'm not well-versed with the methodology, so I'm a bit confused as to why I'm getting the error.
The screen object I'm trying to create:
Code:
#define GAME_SCREEN_TYPES TL6(Image, Button, Slider, \
Dialog_Box, Progress_Bar, Input_Box)
class Game
{
// ...
private:
boost::shared_ptr<Screen<GAME_SCREEN_TYPES> > game_screen;
};
Creating the screen object:
Code:
Game::Game()
: game_screen(Screen<GAME_SCREEN_TYPES>::Create(STGS.GUI_Dir() / "_game_screen.xml"))
{
}
The error(s):
Error 1 error C2440: 'initializing' : cannot convert from 'Type_List<T,U> *' to 'Screen<Type_List> *' e:\dev\boost\boost\smart_ptr\shared_ptr.hpp 179
Error 2 error C2439: 'boost::shared_ptr<T>:
x' : member could not be initialized e:\dev\boost\boost\smart_ptr\shared_ptr.hpp 179
The screen class:
Code:
// Type used to mark the end of a typelist.
struct Null_Type
{
};
// The typelist. For nested typelists type U is a typelist again, so one can
// build typelists of any length.
template<typename T, typename U>
struct Type_List
{
typedef T head;
typedef U tail;
};
// Convenience macros for building typelists.
#define TL1(T1) Type_List<T1, Null_Type >
#define TL2(T1,T2) Type_List<T1, TL1(T2) >
// ...
template<typename Type_List>
class Screen : public Base_Screen
{
public:
static boost::shared_ptr<Screen<Type_List> > Create()
{
return boost::shared_ptr<Screen<Type_List> >(new Type_List());
}
static boost::shared_ptr<Screen<Type_List> > Create(const boost_path& file_name)
{
boost::shared_ptr<Screen<Type_List> > ptr(Create());
ptr->Read(file_name);
return ptr;
}
virtual ~Screen()
{
LOG("Screen at " + file_name.file_string() + " cleaned up.");
}
protected:
Screen() {}
Screen(const boost_path& file_name)
: file_name(file_name)
{
Read(file_name);
LOG("Screen at " + file_name.file_string() + " initialised.");
}
// ...
};
Base_Screen:
Code:
class Base_Screen
: public GUI_Object
, public ticpp::File_Readable
{
public:
virtual ~Base_Screen() {}
};
Cheers.