I have a class called 'VideoPlayer', in which I create an object of another class called 'MenuBar'.
In the 'MenuBar' class I handle mouse events. If one of the buttons in the 'MenuBar' object is clicked, I want to call a function in the 'VideoPlayer' object.
I figured I should send a pointer to the 'VideoPlayer' object to the 'MenuBar' object, so I can access the 'VideoPlayer' object's functions. However, when I include the header file for the 'VideoPlayer' class into the 'MenuBar' class, I get compiler errors:
1 2 3 4 5
1>ClCompile:
1> hvMenuBar.cpp
1>.\src\VideoPlayer.h(51): error C2146: syntax error : missing ';' before identifier 'menu'
1>.\src\VideoPlayer.h(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\src\VideoPlayer.h(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I guess I'm going about it wrong. Any way I try to make a link to the 'parent' class, I get into trouble. I think it's because I'm basically making an #include loop, which includes each other. Simply put I don't know how to do it.
If anyone could point me in the good direction, I'd be very grateful.
Thank you for your reply. It's a very helpful article.
I'm not able to solve the problem though. If I forward declare the VideoPlayer class in the MenuBar class, I can define a pointer to a VideoPlayer object, but I can't call any of VideoPlayer's functions through the pointer. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//hvMenuBar.h
//====================
class VideoPlayer;
class hvMenuBar {
public:
hvMenuBar::ButtonClicked();
VideoPlayer *videoPlayer
}
//hvMenuBar.cpp
//====================
hvMenuBar::ButtonClicked() {
videoPlayer->doFunction(); // <-- error C2027: use of undefined type 'VideoPlayer'
}
Would implementing include guards in all of my header files solve the problem?