3

I am currently working on a project that has several files and is a little complicated (in terms of keeping the inheritance right). I am getting a compile error, and I think it has something to do with references. Here is the error I'm getting at compile time

videotodatastream.cpp: In member function ‘virtual void Wade::VideoToDataStream::getData(std::string&)’:
    videotodatastream.cpp:33: error: no matching function for call to ‘Wade::VideoWrapper::getVideo(Letscher::Video (&)())’
    videowrapper.h:10: note: candidates are: virtual void Wade::VideoWrapper::getVideo(Letscher::Video&)

Here is the line it is complaining about

Letscher::Video vid();
_vid.getVideo(vid); //Problem line

_vid is a private member data of type VideoWrapper&

VideoWrapper& _vid;

VideoWrapper is a pure virtual base class with the following methods:

class VideoWrapper {
    public:
        virtual void setVideo(Letscher::Video& video) = 0;
        virtual void getVideo(Letscher::Video& video) = 0;    
}; 

The child class of VideoWrapper that I am actually using is RawVideo and it looks like this

class RawVideo : public VideoWrapper {
    public:
        RawVideo(Letscher::Video& video);
        virtual void setVideo(Letscher::Video& video);
        virtual void getVideo(Letscher::Video& video);

    private:
        Letscher::Video* _vid;
};

Wade::RawVideo::RawVideo(Letscher::Video& video): _vid(&video) {
}

void Wade::RawVideo::setVideo(Letscher::Video& video) {
  *_vid = video;
}

void Wade::RawVideo::getVideo(Letscher::Video& video) {
  video = *_vid;
}

So when I call _vid.getVideo(vid), I want it to take the Video object vid, and set its value to the private data in RawVideo. But for some reason, the way I am calling this function does not match up with my code.

Any help would be great, thanks.

Matt
  • 31
  • 1

3 Answers3

7

Letscher::Video vid(); does not default construct a variable vid. It declares a function vid which takes no parameters and which returns a Letscher::Video.

You probably want Letscher::Video vid; instead.

lijie
  • 4,811
  • 22
  • 26
  • 1
    Ha! Beat you by 20 seconds! (But +1 because it's the right answer too) This problem is known as C++'s "Most Vexing Parse". – Billy ONeal Dec 10 '10 at 18:40
  • is it vexing? i always thought vexing parses involved constructor arguments.. i.e. more insidious. – lijie Dec 10 '10 at 18:45
  • @lijie: Yep. You can tell from the error message `Wade::VideoWrapper::getVideo(Letscher::Video (&)())` <-- Compiler is looking for a function taking a reference to a function which returns a `Letscher::Video` by value and has no arguments. The vexing parse is any scenario where there is a statement which can look like object construction, but is really a function declaration (because C++ resolves the ambiguity by choosing the function declaration). See the link in my answer (or the entire item on it in Scott Meyers' Effective STL) for more details. – Billy ONeal Dec 10 '10 at 18:49
  • ah ic. so it just refers to the ambiguity. but the default constructor vexing parse seems to be more unique in that it can't be "remedied" by adding parentheses (or is there some way other than removing them? -- i can't think of any) – lijie Dec 10 '10 at 18:51
  • See this answer for the relevant section of the standard: http://stackoverflow.com/questions/2318650/is-no-parentheses-on-a-c-constructor-with-no-arguments-a-language-standard/2318731#2318731 – suszterpatt Dec 10 '10 at 18:53
  • Thanks! Man, I was totally looking in the wrong place. Thanks for pointing out the error of my ways! – Matt Dec 10 '10 at 18:54
  • @ lijie: In C++0x you can say `Letscher::Video vid{};`. Note the curly braces instead of the paranthesis. – fredoverflow Dec 10 '10 at 19:20
4

Letscher::Video vid(); is vexing. That is, it's interpreted as a function declaration for a function called vid which takes no arguments and returns a Letscher::Video by value. Remove the end parenthesis and it should work.

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
2

Search for the most vexing C++ parse on the net. You are not creating any object instead you are declaring a function prototype.

Asha
  • 11,002
  • 6
  • 44
  • 66