0

I have a class template:

template <class T>
class NormalEstimator
{
    public:
        NormalEstimator(pcl::PointCloud<T>::Ptr cloud) : _cloud(cloud) {}

        void computeNormals();
        pcl::PointCloud<pcl::Normal>::Ptr getNormals();
    private:
        typename pcl::PointCloud<T>::Ptr _cloud;
        pcl::PointCloud<pcl::Normal>::Ptr _normals;

        int _kNeighbours;
};

The member functions are declared in the header file as well. When compiling, this gives me the error:

.../normal_estimator.h:12: error: expected ')' before 'cloud'

Am I forgetting something? Do I need to specify 'typename' on the constructor as well in some way or form?

Moos Hueting
  • 650
  • 4
  • 14
  • See [Where and why do I have to put the “template” and “typename” keywords?](http://stackoverflow.com/q/610245/420683) – dyp Mar 10 '14 at 14:44
  • `pcl::PointCloud::Ptr` is a dependant name because T is a template parameter. You have to write `typename pcl::PointCloud::Ptr`. – Simple Mar 10 '14 at 14:45

3 Answers3

1

It's a dependent name. The type ::Ptr is dependent on T. So you have to use "typename" to tell the compiler that the value of ::Ptr is a type.

 NormalEstimator(typename pcl::PointCloud<T>::Ptr cloud) 

This is because as long as T is defined the type of ::Ptr might be anything (a static member / type / static function).

http://en.cppreference.com/w/cpp/language/dependent_name

Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185
0

Did you try this ?

NormalEstimator(typename pcl::PointCloud<T>::Ptr cloud) : _cloud(cloud) {}
Caduchon
  • 4,574
  • 4
  • 26
  • 67
0

Yes, you need typename in the constructor parameter as well because T is a dependent type:

NormalEstimator(typename pcl::PointCloud<T>::Ptr cloud)
//              ^^^^^^^^
David G
  • 94,763
  • 41
  • 167
  • 253