1

I want to derive a class from Microsoft.Kinect.JointCollection class.

public class Derived : JointCollection 
{
    public string NewItem;

    public Derived ()
    {

    }
}

Error:

The type 'Microsoft.Kinect.JointCollection' has no constructors defined.

What is the problem and how can I solve it?

HatSoft
  • 11,077
  • 3
  • 28
  • 43
Sait
  • 19,045
  • 18
  • 72
  • 99

3 Answers3

4

Base class objects are always constructed before any deriving class. Thus the constructor for the base class is executed before the constructor of the derived class.

http://msdn.microsoft.com/en-us/library/ms228387%28v=VS.80%29.aspx

The Microsoft.Kinect.JointCollection class does not contain a public constructor [2] so whenever you attempt to instantiante Derived it fails because a public constructor is not available on the base class.

You could consider wrapping the JointCollection class with your derived class and providing the appropriate methods to access it in Derived that do little more than call methods on JointCollection directly.

Matt Glover
  • 1,347
  • 7
  • 13
  • How can I provide the following property? `Derived derived = new Derived(); int dummy = derived["foo"];` What is the keyword for this? – Sait Jul 08 '12 at 18:34
  • It has been a while since I have done this sort of thing so this may not be exactly right but I think you can use an indexer: http://msdn.microsoft.com/en-us/library/2549tw02%28v=VS.80%29.aspx `public int this[string index]{ /* get and set accessors */ }` – Matt Glover Jul 08 '12 at 18:37
1

I think that error means the class only has an internal constructor defined, so you cannot instantiate it from a different assembly.

doblak
  • 3,036
  • 1
  • 27
  • 22
0

The problem is you are trying to derive from calss that was explicitly designed to prohibit this (which can be done by making all constructors internal/private for expample).

Solution: don't do that. Without information why you want to do that it is hard to offer alternatives.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179