Enforcing derivation constraints between concrete classes

Discussion in 'C++' started by sankhasubhra.dey@gmail.com, Nov 22, 2005.

  1. Guest

    Is it possible to state a constraint that all classes in an
    application which is using my library should be derived publicly from a
    concrete class that I have defined in my library?

    Ex. I have a concrete class X defined in my library. For some reason, I
    want to enforce that all applications which may be defining a new class
    (say Y) and are using my library should be declared as follows:

    class Y:public class X
    {
    .............
    };

    If not, I want to throw a compilation error.

    Thanks,
    Sankha.
     
    , Nov 22, 2005
    #1
    1. Advertising

  2. \/Gogineni\/ Guest

    May be you can enforce users to create classes by a new keyword such as
    CLASS instead of class and define CLASS as following
    #define CLASS(X) class X:public y

    class y
    {
    };

    CLASS(yy)
    {
    };

    There may be complications when you have multiple inheritances and you
    have to check for all the possible cases. BE WARY
     
    \/Gogineni\/, Nov 22, 2005
    #2
    1. Advertising

  3. Guest

    I don't want to change the syntactical use of the language. Is there
    some instruction that I can pass to the compiler to check for such a
    thing? If I had a template which somebody wanted to instantiate, it is
    easy to perform this check, without any particular instruction to the
    compiler. Is there some alternative for concrete classes?

    Thanks,
    Sankha.
     
    , Nov 22, 2005
    #3
  4. wrote:
    > Is it possible to state a constraint that all classes in an
    > application which is using my library should be derived publicly from a
    > concrete class that I have defined in my library?


    Remind me never to use your library, That is a horrendous constraint to
    put on the user.

    >
    > Ex. I have a concrete class X defined in my library. For some reason, I
    > want to enforce that all applications which may be defining a new class
    > (say Y) and are using my library should be declared as follows:
    >
    > class Y:public class X
    > {
    > .............
    > };
    >
    > If not, I want to throw a compilation error.


    Anyway impossible.

    john
     
    John Harrison, Nov 22, 2005
    #4
  5. * John Harrison:
    > wrote:
    > > Is it possible to state a constraint that all classes in an
    > > application which is using my library should be derived publicly from a
    > > concrete class that I have defined in my library?

    >
    > Remind me never to use your library, That is a horrendous constraint to
    > put on the user.
    >
    > >
    > > Ex. I have a concrete class X defined in my library. For some reason, I
    > > want to enforce that all applications which may be defining a new class
    > > (say Y) and are using my library should be declared as follows:
    > >
    > > class Y:public class X
    > > {
    > > .............
    > > };
    > >
    > > If not, I want to throw a compilation error.

    >
    > Anyway impossible.


    Ahem, I think the following library function:

    void foo( X const& someObject );

    does just what the OP actually requests -- but perhaps not what's
    _meant_... ;-)

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Nov 22, 2005
    #5
  6. Guest

    Hi,

    You needn't feel so terrified about my library ;-)........I only intend
    to use certain mixin classes defined in my library for performing
    bookkeeping operations to prevent resource leaks...it is absolutely
    transparent to the user. But I don't want to be dependent on the user
    to remember to derive from my class.....I would prefer to do it quietly
    behind the scenes, if possible.

    Sankha.
     
    , Nov 22, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter the Swede

    JDOM simple concrete example

    Peter the Swede, Nov 12, 2003, in forum: Java
    Replies:
    1
    Views:
    510
    Christophe Vanfleteren
    Nov 12, 2003
  2. Steven T. Hatton
    Replies:
    12
    Views:
    1,699
    Jonathan Turkanis
    Aug 20, 2004
  3. Anitha
    Replies:
    7
    Views:
    7,739
    Dave Moore
    Feb 1, 2005
  4. Christopher

    nested classes and derivation

    Christopher, Feb 8, 2008, in forum: C++
    Replies:
    2
    Views:
    353
    Grizlyk
    Feb 9, 2008
  5. Rahul Kumar
    Replies:
    1
    Views:
    104
    ara.t.howard
    Sep 13, 2010
Loading...

Share This Page