开发者

C++ and references

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 compla开发者_StackOverflow中文版ining 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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜