Enforcing derivation constraints between concrete classes

S

sankhasubhra.dey

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.
 
G

\/Gogineni\/

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
 
S

sankhasubhra.dey

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.
 
J

John Harrison

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
 
A

Alf P. Steinbach

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


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_... ;-)
 
S

sankhasubhra.dey

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.
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top