Reputation: 1
i want to ask about typedef variable in C++
ok, right now i'm using PCL and i want to separate the code into .h and .cpp
here's my .h file
template <typename PointType>
class OpenNIViewer
{
public:
typedef pcl::PointCloud<PointType> Cloud;
typedef typename Cloud::ConstPtr CloudConstPtr;
...
...
CloudConstPtr getLatestCloud ();
...
...
};
then the definition of getLatestCloud() on other .cpp file
template <typename PointType>
CloudConstPtr OpenNIViewer<PointType>::getLatestCloud ()
{
...
}
then i got C4430 error because it doesn't recognize return type CloudConstPtr
sorry for the silly question :D
Upvotes: 0
Views: 341
Reputation: 40643
Change getLatestCloud
to:
template <typename PointType>
typename OpenNIViewer<PointType>::CloudConstPtr
OpenNIViewer<PointType>::getLatestCloud ()
{
...
}
When reading CloudConstPtr
, the compiler does not yet know which scope it should be looking in, so it needs to be qualified.
Upvotes: 1
Reputation: 361812
CloudConstPtr
is a nested type, so you need qualify it with the scope also:
template <typename PointType>
typename OpenNIViewer<PointType>::CloudConstPtr OpenNIViewer<PointType>::getLatestCloud ()
{
...
}
But then it still would not work: it is because you've defined it in .cpp
file. In case of template, the definition should be available in .h
file itself. The simpliest way to do that is to define each member function in the class itself. Don't write .cpp
file.
Upvotes: 2