-3

I am having issues calling a parent constructor from an inherited class.

Here is how I am trying to call the function:

pFile = fopen(filePath.c_str(), "r");
if (pFile == NULL) {
    std::cout << "Error opening file" << std::endl;
}

StatusObj status();

Subclass mcrf_(pFile, status);

and here is the subclass definition

class Subclass : public Superclass {
public:
    Subclass(FILE * f_ptr, StatusObj status) : SuperClass(f_ptr, status) {}
};

the SuperClass's constructor looks like this:

SuperClass( FILE * input, StatusObj & status, uint64_t src_id=0 );

So at this point I think I am doing everything right, however when I try to compile I am getting the following error:

/main.cpp:152: error: no matching function for call to ‘SubClass(FILE*&, StatusObj (&)())’
/SubClass.h:23: note: candidates are: SubClass(FILE*, StatusObj)

I know I have a pointer or reference off somewhere - can anyone lend a hand and help me locate it?

Thanks!

wakey
  • 2,283
  • 4
  • 31
  • 58

1 Answers1

2

(Most) vexing parse for StatusObj status(); which is a function declaration.

Use

StatusObj status;

or

StatusObj status{};
Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • 1
    **NOT** a most vexing parse, though. – SergeyA Jun 14 '16 at 17:37
  • @SergeyA Inline function definition? – πάντα ῥεῖ Jun 14 '16 at 17:39
  • @πάνταῥεῖ, MVP is traditionally reserved for the cases like `A a(B());` – SergeyA Jun 14 '16 at 17:48
  • @SergeyA Ah, I see. I think I never got the MVP issue up to it's end. But what would be the correct term? `StatusObj status();` is an _inline funciotn declaration_? (definition was merely a typo above). – πάντα ῥεῖ Jun 14 '16 at 17:51
  • 1
    @πάνταῥεῖ I would simply say *a function declaration*, to avoid confusion with `inline` functions. MVP is not a standard term either, but *most* there relates to the complexity of the case - and nothing is complex about straightforward function declaration. (what else `A x();` could be after all?) – SergeyA Jun 14 '16 at 17:54