H
Hunk
Hi
I have a question on usage of forward declarations of templates. While
searching through this group , people suggested using forward
declarations and typedefs for templates as
// in myfile.h
template<typename T,typename R>
class some_class;
typedef some_class<int,float> my_class;
then use my_class as an instance in the program. The advantage in this
is obviously i dont have to include the header file declaring
some_class. This would help in recompilation dependencies.
Now i tried out the same as shown below. Note: i have mentioned the
errors in comments
//c_reg.h
template<typename T,typename R>
class c_reg
{
virtual R get_data(T p_data);
virtual void set_data(T , R);
}
template<typename T,typename R> R c_reg::get_data(T p_data)
{
... //do something
}
template <typename T,typename R> void c_reg::set_data(T p_key, R
p_data)
{
... //do something
}
//end of c_reg.h
------------------------------------------------------------------------------------
//c_reg_init.h
// below forward declaration gives error
// error is "declaration of struct c_my_reg"
template<T,R>
class c_reg;
typedef c_reg<int,std::string> c_my_reg;
// also gives error here saying
// invlaid use of undefined type c_my_reg
template<typename T>
class c_reg_init : public c_my_reg
{
void set_data (int, std::string)
}
template<typename T> void c_reg_init<T>::set_data(int, std::string)
{
...//do something
}
//end of c_reg_init.h
Now as seen above, i'm tyring to avoid inclusion of c_reg.h in
c_reg_init header file. But using the forward declaration syntax gives
errror mentioned above. It assumes the forward declared template class
c_reg to be a struct i dont know why.
What i want to basically do is hide the template header file so that i
can give the user a interface. In this interface i should be able to
just forward declare the template class
Is there a way around?
I have a question on usage of forward declarations of templates. While
searching through this group , people suggested using forward
declarations and typedefs for templates as
// in myfile.h
template<typename T,typename R>
class some_class;
typedef some_class<int,float> my_class;
then use my_class as an instance in the program. The advantage in this
is obviously i dont have to include the header file declaring
some_class. This would help in recompilation dependencies.
Now i tried out the same as shown below. Note: i have mentioned the
errors in comments
//c_reg.h
template<typename T,typename R>
class c_reg
{
virtual R get_data(T p_data);
virtual void set_data(T , R);
}
template<typename T,typename R> R c_reg::get_data(T p_data)
{
... //do something
}
template <typename T,typename R> void c_reg::set_data(T p_key, R
p_data)
{
... //do something
}
//end of c_reg.h
------------------------------------------------------------------------------------
//c_reg_init.h
// below forward declaration gives error
// error is "declaration of struct c_my_reg"
template<T,R>
class c_reg;
typedef c_reg<int,std::string> c_my_reg;
// also gives error here saying
// invlaid use of undefined type c_my_reg
template<typename T>
class c_reg_init : public c_my_reg
{
void set_data (int, std::string)
}
template<typename T> void c_reg_init<T>::set_data(int, std::string)
{
...//do something
}
//end of c_reg_init.h
Now as seen above, i'm tyring to avoid inclusion of c_reg.h in
c_reg_init header file. But using the forward declaration syntax gives
errror mentioned above. It assumes the forward declared template class
c_reg to be a struct i dont know why.
What i want to basically do is hide the template header file so that i
can give the user a interface. In this interface i should be able to
just forward declare the template class
Is there a way around?