473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Nov 22 '05 #1
5 1240
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

Nov 22 '05 #2
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 '05 #3
sa**************@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
Nov 22 '05 #4
* John Harrison:
sa**************@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?
Nov 22 '05 #5
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 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Saqib Ali | last post by:
I have created 2 tables in my MySQL database. A_TAB and B_TAB. They have auto-incrementing integer primary keys respectively named A_ID & B_ID. When I created B_TAB, I declared a field named A_ID...
1
by: Dietmar Gräbner | last post by:
Hi Right now I'm dealing with derivation by restriction and I have some questions concerning the attribute property use in context of the derivation. Consider following Schema: <xs:schema...
9
by: mead | last post by:
What kind of classes is qualified as "concrete classes"? When should a member function in a class defined as "pure virtual" and when as "virtual"? Thanks!
7
by: Anitha | last post by:
What are abstract classes and concrete classes
11
by: andrew queisser | last post by:
I've read some material on the upcoming Generics for C#. I've seen two types of syntax used for constraints: - direct specification of the interface in the angle brackets - where clauses I...
0
by: Andreas Damm | last post by:
I need to determine how closely one type is related to another for a custom System.Reflection.Binder I am writing. This measure expresses through how many classes one type is inheriting from...
2
by: Frosty | last post by:
Howto make datagrid enforce rules of xml schema? Created xml schema in the designer. Constraints created there using the following <xs:simpleType name="zipcode"><xs:restriction...
2
by: Harold Howe | last post by:
Howdy all, I am getting a compiler error regarding a consrained conversion. It complains that it can't make the type conversion, even though the generic type argument inherits from the target of...
4
by: Ian Lazarus | last post by:
Why are constraints needed? In C++, an attempt to use a non-existing method will cause a compiler error. Isn't that true in C# also?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.