# How to declare

This topic is 4149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have been working on a geometric library that is available here... http://codestash.googlepages.com/ezgeom The problem that I am running into is that in the main.h header file I have... #include "../ezGeom/Lib/clPoint_3d.h" . . . #include "../ezGeom/Lib/clVector_3d.h" So inside the vector class I have no problems using a point because the point class has already been declared. But I want to create a member function in the point class that has a vector as its parameters. Can this be done, do I have to make the function a friend function? Any help would be appreciated.

##### Share on other sites
You have what is know as a circular dependancy. This can be broken using forward declarations. Lets assume we have classes A and B thus:
// A.h#include "B.h"class A{private:    B m_a_member_of_type_B; // need to include "B.h" because the compiler needs                            // to know how big B is.};// B.hclass B{public:    void AFunction (class A parameter_of_type_A); // a forward declaration!                                                  // No need to #include "A.h"};// B.cpp#include "A.h"void B::AFunction (A parameter_of_type_A){    // body of function}

You can also do the following:
// B.hclass A; // a forward declaration!class B{public:    void AFunction (A parameter_of_type_A); // OK to use "A" instead of "class A" since it's been forward declared above.};

If you're using namespaces, then the correct way to forward declare is:
// C.hnamespace BNamespace{    class B;}class C{public:    void Function (BNamespace::B parameter);};

Skizz

##### Share on other sites
Cool, thanks. I'll try this out.