473,396 Members | 1,892 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,396 software developers and data experts.

generic base class where T is other generic base class

I have an abstract generic class:

Expand|Select|Wrap|Line Numbers
  1.     public abstract class SomeBaseClass<U,V>
  2.     {
  3.     }
I want to create other generic class:

Expand|Select|Wrap|Line Numbers
  1.     public abstract class SomeOtherBaseClass<T1, T2> where T1 : SomeBaseClass<U,V>
  2.     {
  3.         private readonly T1 _someBaseClass;
  4.  
  5.         public SomeOtherBaseClass(T1 someBaseClass)
  6.         {
  7.             _someBaseClass = someBaseClass;
  8.         }
  9.     }
How can i do this?
Nov 20 '10 #1

✓ answered by Christian Binder

The typeparams U and V aren't defined in SomeOtherBaseClass.

You could define them in SomeOtherBaseClass like
public abstract class SomeOtherBaseClass<T1, T2, U, V> where T1 : SomeBaseClass<U,V>

Or you create a non-generic base class

Expand|Select|Wrap|Line Numbers
  1. public abstract class SomeBaseClass { }
  2.  
  3. public abstract class SomeBaseClass<U,V> : SomeBaseClass
  4. {
  5. }
  6.  
  7. public abstract class SomeOtherBaseClass<T1, T2> where T1 : SomeBaseClass { ... }
  8.  

1 1845
Christian Binder
218 Expert 100+
The typeparams U and V aren't defined in SomeOtherBaseClass.

You could define them in SomeOtherBaseClass like
public abstract class SomeOtherBaseClass<T1, T2, U, V> where T1 : SomeBaseClass<U,V>

Or you create a non-generic base class

Expand|Select|Wrap|Line Numbers
  1. public abstract class SomeBaseClass { }
  2.  
  3. public abstract class SomeBaseClass<U,V> : SomeBaseClass
  4. {
  5. }
  6.  
  7. public abstract class SomeOtherBaseClass<T1, T2> where T1 : SomeBaseClass { ... }
  8.  
Nov 22 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
9
by: Martin Herbert Dietze | last post by:
Hello, I would like to implement a callback mechanism in which a child class registers some methods with particular signatures which would then be called in a parent class method. In...
3
by: Brad Navarro | last post by:
OK, I may be asking for the impossible, but I'll give it a shot: For a case like this: using System.Data.SqlClient; abstract class Base { private SqlConnection DBConnect; Base(string...
3
by: J.J. Feminella | last post by:
(Please disregard the previous message; I accidentally sent it before it was completed.) I have source code similar to the following. public class Vehicle { protected string dataV; // ......
1
by: Mark McDonald | last post by:
This question kind of follows on from Mike Spass’ posting 10/11/2004; I don’t understand why you can’t declare an implicit operator to convert a base class to a derived class. The text...
4
by: matty.hall | last post by:
I have two classes: a base class (BaseClass) and a class deriving from it (DerivedClass). I have a List<DerivedClass> that for various reasons needs to be of that type, and not a List<BaseClass>....
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
4
by: Charles Churchill | last post by:
I apologize if this question has been asked before, but after about half an hour of searching I haven't been able to find an answer online. My code is beloiw, with comments pertaining to my...
9
by: tadmill | last post by:
Is it possible to pass a generic parameter of the same class to to its constructor, where the "T" type passed in the constructor is different than the "T" type of the instanced class? ie, ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.