tags:

views:

103

answers:

2
//portl.cpp
namespace FAWN {
namespace Sys{

class PortListner {

....
Connecter::ConPtr _cur_con; - the main problem is here

...

//con.cpp
namespace FAWN {
namespace Sys {

class Connecter {

.....
public:

 typedef boost::shared_ptr<Connecter> ConPtr;

...

Moreover, portl.cpp file is included into some other "main" sourse file. And this "other-main" file includes con.cpp too. So if I include con.cpp to portl.cpp - I define Connecter twice (in portl and in main). If I do not include it, compilator doesn't know what Connecter::ConPtr (or FAWN::sys::Connecter::ConPtr) means and try to use it as defenition of method.

+2  A: 

Put the class Connecter (which you should probably rename to Connector) into a header file (.h instead of .cpp) and add include guards into the file. That is, at the beginning of your con.h file, add lines

#ifndef CON_H_INCLUDED
#define CON_H_INCLUDED

and at the very end, add the line

#endif

This way, even if you #include con.h twice, the second time it will not get read because the symbol CON_H_INCLUDED has been defined on the first time so the #ifndef-#endif pair hides the content.

This is the common way in C++: put class declarations in .h files that get #included in .cpp files that then actually define the functions.

jk
I've already splited up my sourses into definition and decloration (I hope it's called this way in English).The main troble is that I NEED to include it in portlistner.h - or it won't find Connector (thanks... I'll change) as a class at all. And tells me, that Connector is not a namespase, or class-name.
MInner
Did you add the include guards? Because after adding those you can then include `con.h` into your `portl.cpp` (or that's probably `portl.h` if you've split the declarations out) without having a double definition even if you later include `con.h` again in a file where you've included `portl.h`.
jk
I've been writing a long comment full of thanks but internet turned off and though it away..Thanks for jk, Igor Zevaka and goldPseudo.
MInner
PS It works)PPS It's pitty, but I can't vote up.
MInner
+1  A: 

Here is how it should look:

#ifndef PORTAL_H
#define PORTAL_H
#include "con.h"
//portl.h
namespace FAWN {
namespace Sys{

  class PortListner {

....
    //might need to specify Connector's namespace  fully here
    FAWN::Sys::Connecter::ConPtr _cur_con; 
...
  };
}
#endif //PORTAL_H

//con.h
#ifndef CON_H
#define CON_H
namespace FAWN {
namespace Sys {

  class Connecter {

  .....
  public:

    typedef boost::shared_ptr<Connecter> ConPtr;

  };
}
#endif //CON_H
Igor Zevaka