hiding type in class declaration

  • Thread starter Lukasz Slusarczyk
  • Start date
L

Lukasz Slusarczyk

I'm writting sth.h file like that:

class sth {
public:
...
private:
list<sthelse> somevariable
};

and implement it in file sth.cpp,
but I have to write #include <list> in sth.h

I wold rather have something like that:

in sth.h:
class sth {
public:
...
private:
sth_type somevariable;
};

and the line
#include <list>
only in sth.cpp file

What's the way I should write sth.h and sth.cpp to gain that?
Great thanks for any answer to this basic question :)
 
J

Jonathan Mcdougall

I'm writting sth.h file like that:
class sth {
public:
...
private:
list<sthelse> somevariable
};

and implement it in file sth.cpp,
but I have to write #include <list> in sth.h

So what ?
I wold rather have something like that:

in sth.h:
class sth {
public:
...
private:
sth_type somevariable;
};

Make sth_type another class, but you'll have to include the class's
header in order to use it, and that header would include <list>
anyways. The solution would be to make 'somevariable' an opaque
pointer to that class, but then that would be quite inneficient.

What is the problem? Maybe we'll find another way.


Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top