Base class and a advanced case theirs of using

  • Thread starter =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki
  • Start date
?

=?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

We has this one class:
class Socket
{
 public:
    Socket(Socket&);
};
and it's two class
class Buffer:private Socket
{
  public:
        Buffer(Socket&soc):Socket(soc){}
        Buffer(Buffer const&buf):Socket(/*i co dalej*/){};
};
We have it's code
 Socket soc;
 Buffer buf1(soc);
 Buffer buf2=buf1;
That is a class of socket it has to be common for this objekt of variable
buff1 and buff2,that is their take up a common memory(it's property of
object of Socket).
Question:What have it got to be to a code it was a correct code of C++
language?
Thanks in advance.
Miros³aw Makowiecki
 
V

Victor Bazarov

Miros³aw Makowiecki said:
We has this one class:
class Socket
{
public:
Socket(Socket&);
};
and it's two class
class Buffer:private Socket
{
public:
Buffer(Socket&soc):Socket(soc){}
Buffer(Buffer const&buf):Socket(/*i co dalej*/){};
};
We have it's code
Socket soc;
Buffer buf1(soc);
Buffer buf2=buf1;
That is a class of socket it has to be common for this objekt of
variable buff1 and buff2,that is their take up a common memory(it's
property of object of Socket).
Question:What have it got to be to a code it was a correct code of C++
language?

As I understand the question, you suspect that the code [you posted]
is somehow incorrect from C++ point of view. Well, the only thing I
can see is that the second constructor of 'Buffer' attempts to
default-initialise the 'Socket' base class, which has no default
c-tor. There is no way to fix that easily without knowing why the
'Socket's constructor needs a reference to non-const. Perhaps it
could take a reference to const, in which case you can write the
second 'Buffer' c-tor as

Buffer(Buffer const &buf) : Socket(buf) {}

.. Of course, it would help immensely if you posted real code.

V
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top