Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Enforcing derivation constraints between concrete classes

Reply
Thread Tools

Enforcing derivation constraints between concrete classes

 
 
sankhasubhra.dey@gmail.com
Guest
Posts: n/a
 
      11-22-2005
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 Yublic class X
{
.............
};

If not, I want to throw a compilation error.

Thanks,
Sankha.

 
Reply With Quote
 
 
 
 
\/Gogineni\/
Guest
Posts: n/a
 
      11-22-2005
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 Xublic 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

 
Reply With Quote
 
 
 
 
sankhasubhra.dey@gmail.com
Guest
Posts: n/a
 
      11-22-2005
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.

 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      11-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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 Yublic class X
> {
> .............
> };
>
> If not, I want to throw a compilation error.


Anyway impossible.

john
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-22-2005
* John Harrison:
> (E-Mail Removed) 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 Yublic 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?
 
Reply With Quote
 
sankhasubhra.dey@gmail.com
Guest
Posts: n/a
 
      11-22-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. Bobby Edward ASP .Net 4 11-03-2008 10:53 PM
Gridview error: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. Bobby Edward ASP .Net 1 10-14-2008 04:09 AM
nested classes and derivation Christopher C++ 2 02-09-2008 07:21 PM
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. bazzer ASP .Net 1 04-06-2006 01:31 PM
portected access: template derivation vs. class derivation Steven T. Hatton C++ 12 08-20-2004 04:56 AM



Advertisments