0

this works:

shared_ptr<ofxDTangibleBase> sp(new ofxDTangibleBase(colorBlob, "ofxDTangibleBase", detectColor, workImg));

But if i do it with make_shared:

shared_ptr<ofxDTangibleBase> sp = make_shared<ofxDTangibleBase>(colorBlob, "ofxDTangibleBase", detectColor, workImg);

I get ''ofxDTangibleBase' does not refer to a value' I have looked for a fix but i found people with problems like having to many parameters etc.

Do i overlook something?

Edit:

the constructor looks like this:

ofxDTangibleBase(const ofxCvBlob& base, const char *className, ofxDDetectColor *detectColor, const ofxCvGrayscaleImage *thresholdImage) : ofxCvBlob(base) {

And the class extends another class:

class ofxDTangibleBase : public ofxCvBlob {
clankill3r
  • 9,146
  • 20
  • 70
  • 126

1 Answers1

0

Hard to say, maybe try to reduce the code and see if that helps to clarify a smaller test case. E.g. this, which is built after your example, compiles fine. Do you have all the proper declarations visible? Maybe something is forward declared, although that should not be an issue.

#include <memory>

class CHorse
{
public:
    CHorse()
    {
    }
    CHorse(const CHorse& Horse)
    {
    }
};

class CSlowHorse : public CHorse
{
public:
    CSlowHorse(const CHorse& Horse, const char* pHorseName, bool bVerySlowHorse, int nLegCount) : CHorse(Horse)
    {
    }
};

int main(int argc, char* argv[])
{
    CHorse Horse;
    std::shared_ptr<CSlowHorse> pSlowHorse = std::make_shared<CSlowHorse>(Horse, "a slow horse", false, 4);
    return 0;
}

P.S.: For people wanting to comment that this is a bad example - yes it is, if the std::shared_ptr instance is passed on and actually keeps a reference to CHorse after the stack object is deleted it will result very poorly, this is just to show that a similar example compiles.

Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71