Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Enforcing derivation constraints between concrete classes (http://www.velocityreviews.com/forums/t449996-enforcing-derivation-constraints-between-concrete-classes.html)

sankhasubhra.dey@gmail.com 11-22-2005 05:53 AM

Enforcing derivation constraints between concrete classes
 
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.


\/Gogineni\/ 11-22-2005 06:18 AM

Re: Enforcing derivation constraints between concrete classes
 
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


sankhasubhra.dey@gmail.com 11-22-2005 06:32 AM

Re: Enforcing derivation constraints between concrete classes
 
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.


John Harrison 11-22-2005 08:07 AM

Re: Enforcing derivation constraints between concrete classes
 
sankhasubhra.dey@gmail.com 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

Alf P. Steinbach 11-22-2005 08:15 AM

Re: Enforcing derivation constraints between concrete classes
 
* John Harrison:
> sankhasubhra.dey@gmail.com 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?

sankhasubhra.dey@gmail.com 11-22-2005 10:31 AM

Re: Enforcing derivation constraints between concrete classes
 
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.



All times are GMT. The time now is 10:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.