2 classes that are dependant on each other

Started by
15 comments, last by b1gjo3 15 years, 11 months ago
in this class, class A is EdsCam, class B is EVFView

my forward declaration
class EVFView;


here is the "SomeFunc"
void EdsCam::_ShowEVFWindow(){	EVFView* liveView = new EVFView(this);}


here is class B which is EVFView
class EVFView : public Window{public:	EVFView(EdsCam* cam);//..EVFView::EVFView(EdsCam* cam):Window("Live View", 500, 410){	this->cam = cam;	SetupWndClass(LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_BIG)), LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SM)));	InitWindow();}


errors are
edscam.hpp(236) : error C2514: 'EVFView' : class has no constructors
edscam.hpp(11) : see declaration of 'EVFView'

it looks like my forward declaration is not right, what would it be?
Advertisement
Quote:Original post by rip-off
Post the actual errors.

If you have changed the code quite a bit, post the updated code.

This works for me:
*** Source Snippet Removed ***


thats exactly what i need, except that both classes need to have private member of each other.
Why the dependency between the two classes? What are you trying to do? What is the purpose of these classes and what are they expected to do. I'm willing to bet that you could combine/modify them to something cleaner (refactor).

Cheers,

Bob

[size="3"]Halfway down the trail to Hell...
EdsCam is a class that can control all the properties of the EDS series of Canon digital cameras.

EVFView is a window that will be used to show live view images from the certain EdsCam object.
Quote:Original post by b1gjo3
EdsCam is a class that can control all the properties of the EDS series of Canon digital cameras.

EVFView is a window that will be used to show live view images from the certain EdsCam object.

So, you need one EdsCam per physical camera, and you need one EVFView per window on the screen. A camera cares not about the windows on the screen, so the AdsCam does not need to know about te EVFView class.

I suspect you need something more akin to this.
  class EdsCam  {    // ...  };  class EVFView  {  public:    EVFView(EdsCam& camera)    : m_camera(camera)    {       // ...    }  private:    EdsCam& m_camera;  };  int main(int, char*[])  {    EdsCam camera;    EVFView view(camera);    // ...  }

Stephen M. Webb
Professional Free Software Developer

The file that contains the function definitions for EdsCam needs to include the header file that contains the declaration for EVFView.

A forward declaration only allows you to create a pointer or a reference to the class that you forward declare. If you need to create instances of it or make function calls to it, you need to include it's header file.
yes thank you, i had to adjust header files and i finally got it working. Thanks again everyone for you help

This topic is closed to new replies.

Advertisement