3

I'm trying to forward declare couple of dlib classes, but it seems what I'm doing is wrong. Currently I have tried this:

"myheader.h":

namespace dlib 
{
    class frontal_face_detector;
    class shape_predictor;
    class full_object_detection;
}

class MyClass:
{
public: 
    void start();

private:
    void test(dlib::full_object_detection* result);

dlib::fronta_face_detector* detector;
dlib::shape_predictor predictor;
dlib:: full_object_detection result;
};

and in myheader.cpp:

#include <dlib/image_io.h>
#include <dlib/opencv.h>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include "myheader.h"

MyClass::MyClass()
{
    this->detector = new dlib::frontal_face_detector();
    this->predictor = new dlib::shape_predictor();
}
void MyClass:test(dlib::full_object_detection * result)
{
  //...
}

but this doesn't work apparently, what am I missing here? Is it because it's defined not as a class but as a typedef?

    typedef object_detector<scan_fhog_pyramid<pyramid_down<6> > > frontal_face_detector;

If so, how should I go about this aside from pimpling MyClass?

halfer
  • 19,824
  • 17
  • 99
  • 186
Hossein
  • 24,202
  • 35
  • 119
  • 224
  • 1
    As you are using the types as class members they can't be forward declared. You can replace the members with pointers or use pimpl to hide them completely – Alan Birtles Aug 17 '20 at 06:28
  • @AlanBirtles Thanks alot really appreciate it, so the only way would be pimpl. if I defined the types as void* and then initialize them with actual data in constructor, would that be a good idea as well? (casting and recasting aside). my worry is that, since the object is local to the constructor, the void* will point to invalid location outside of constructor. is it right (sorry its been couple of years since I worked in c++ and things are a bit fuzzy now!) – Hossein Aug 17 '20 at 06:32
  • there wouldn't be any benefit to using `void*`, typed pointers would work just as well – Alan Birtles Aug 17 '20 at 07:11
  • @AlanBirtles yeah thanks, really appreciate your time. – Hossein Aug 17 '20 at 07:23

0 Answers0