Topic: PARTIAL CLASS DEFINITIONS


Author: rado42@my-deja.com
Date: 1999/06/11
Raw View
Hello everybody,

Here I would like to make a proposal for C++ extension and to suggest a
discussion about it.

As all we know, one cannot access the members (both data and function)
of a class if  the class definition is not visible, e.g.

class MyClass* a;
a->myMember();


will cause a compilation error: the compiler does not know that MyClass
has myMember(),  even if actually this is the case.

That means that in order to use ANY class member, the code must see the
ENTIRE class definition: e.g.


class MyClass
{
stuff
stuff
more stuff
private stuff





Author: comeau@panix.com (Greg Comeau)
Date: 1999/06/11
Raw View
In article <7jqopn$cfu$1@nnrp1.deja.com> rado42@my-deja.com writes:
>Here I would like to make a proposal for C++ extension and to suggest a
>discussion about it.
>
>As all we know, one cannot access the members (both data and function)
>of a class if  the class definition is not visible, e.g.
>
>class MyClass* a;
>a->myMember();
>
>
>will cause a compilation error: the compiler does not know that MyClass
>has myMember(),  even if actually this is the case.
>
>That means that in order to use ANY class member, the code must see the
>ENTIRE class definition: e.g.
>
>
>class MyClass
>{
>stuff
>stuff
>more stuff
>private stuff

I'm not clear on your proposal.  What is it, would you like to see
that the class definition does not have to be visible (in whole or in part)?

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
     Producers of Comeau C/C++ 4.2.38 -- New Release!  We now do Windows too.
    Email: comeau@comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
                *** WEB: http://www.comeaucomputing.com ***


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Pete Becker <petebecker@acm.org>
Date: 1999/06/12
Raw View
Greg Comeau wrote:
>
> In article <7jqopn$cfu$1@nnrp1.deja.com> rado42@my-deja.com writes:
> >Here I would like to make a proposal for C++ extension and to suggest a
> >discussion about it.
> >
> >As all we know, one cannot access the members (both data and function)
> >of a class if  the class definition is not visible, e.g.
> >
> >class MyClass* a;
> >a->myMember();
> >
> >
> >will cause a compilation error: the compiler does not know that MyClass
> >has myMember(),  even if actually this is the case.
> >
> >That means that in order to use ANY class member, the code must see the
> >ENTIRE class definition: e.g.
> >
> >
> >class MyClass
> >{
> >stuff
> >stuff
> >more stuff
> >private stuff
>
> I'm not clear on your proposal.  What is it, would you like to see
> that the class definition does not have to be visible (in whole or in part)?
>

You shouldn't need to see the entire proposal. Can't you just figure it
out from what was presented? Just as the compiler could figure out what
MyClass really looks like, just from seeing how it's used.

--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "rob" <post_replies_ple@se.thanks>
Date: 1999/06/12
Raw View
It seems you've submitted a partial posting about partial class definitions
here; the message just seems to cut off at the end there.

Anyway, have your class inherit from an abstract interface class that
supports only the interface you want available to the other object like
this:

class Number_Readonly
{
public:
    int get() const = 0;
};

class Number : public Number_Readonly
{
public:
    int set(int x) { m_x = x; };
    int get() const { return m_x; };
protected:
    int m_x;
};

/// in some other file...

#include "Number_Readonly.h"
#include <iostream>

void show_value(const Number_Readonly & n)
{
    cout << n.get() << endl;
}

You can get the value from Number without even knowing
it's a Number; you get only a pointer/reference to a
Number_Readonly interface.

rob.

rado42@my-deja.com wrote in message <7jqopn$cfu$1@nnrp1.deja.com>...
<snip>
>That means that in order to use ANY class member, the code must see the
>ENTIRE class definition: e.g.
>
>
>class MyClass
>{
>stuff
>stuff
>more stuff
>private stuff
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]