I code in wpf c#  partial class A : userControl { }  partial class B : userControl  { }   But i have to make an inheritance between them   partial class A : userControl { }  partial class B : A { }   But when i do that i have an error saying :  Partial declarations of B must not specify different base classes
91698
I am fairly new to WPF and I am having a problem with inheriting from a user control.  I created a User Control and now I need to inherit from that control and add some more functionality.  Has anyone does this sort of thing before?  Any help would be greatly appreciated.  Thank you
92393
I know how to create a custom user control in WPF but how can I make it so that someone can provide an ItemTemplate?  I have a user control that is a mixture of several other WPF controls, one of them being a ListBox. I'd like to let the user of the control specify the content of the list box but I'm not sure how to pass that information through.  EDIT: The accepted answer works with the following correction:  &lt;UserControl x:Class="WpfApplication6.MyControl"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:src="clr-namespace:WpfApplication6"&gt;     &lt;ListBox ItemTemplate="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type src:MyControl}}, Path=ItemsSource}" /&gt; &lt;/UserControl&gt;
6639
What's the difference between:  class Child(SomeBaseClass):     def __init__(self):         super(Child, self).__init__()   and:  class Child(SomeBaseClass):     def __init__(self):         SomeBaseClass.__init__(self)   I've seen super being used quite a lot in classes with only single inheritance. I can see why you'd use it in multiple inheritance but am unclear as to what the advantages are of using it in this kind of situation.
54456
Does anyone know why typedefs of class names don't work like class names for the friend declaration?  class A { public: };  class B : public A { public:    typedef A SUPERCLASS; };  typedef A X;  class C { public:    friend class A;             // OK    friend class X;             // fails    friend class B::SUPERCLASS; // fails };
123439
Ok, bear with me guys and girls as I'm learning.  Here's my question.  I can't figure out why I can't override a method from a parent class.  Here's the code from the base class (yes, I pilfered the java code from an OOP book and am trying to rewrite it in C#).  using System;  public class MoodyObject {     protected String getMood()     {         return "moody";     }      public void queryMood()     {         Console.WriteLine("I feel " + getMood() + " today!");     } }   and here are my other 2 objects that inherit the base class (MoodyObject):  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ConsoleApplication1 {     public class SadObject: MoodyObject     {         protected String getMood()         {             return "sad";         }          //specialization         public void cry()         {             Console.WriteLine("wah...boohoo");         }     } }   And:  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ConsoleApplication1 {     public class HappyObject: MoodyObject     {         protected String getMood()         {             return "happy";         }          public void laugh()         {             Console.WriteLine("hehehehehehe.");         }     } }   and here is my main:  using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespace ConsoleApplication1 {     class Program     {         static void Main(string[] args)         {             MoodyObject moodyObject = new MoodyObject();             SadObject sadObject = new SadObject();             HappyObject happyObject = new HappyObject();              Console.WriteLine("How does the moody object feel today?");             moodyObject.queryMood();             Console.WriteLine("");             Console.WriteLine("How does the sad object feel today?");             sadObject.queryMood();             sadObject.cry();             Console.WriteLine("");             Console.WriteLine("How does the happy object feel today?");             happyObject.queryMood();             happyObject.laugh();         }     } }   As you can see, pretty basic stuff, but here's the output:     How does the moody object feel today?   I feel moody today!      How does the sad object feel today? I   feel moody today! wah...boohoo      How does the happy object feel today?   I feel moody today! hehehehehehe.   Press any key to continue . . .   Not as I expected.  I've tried to make the base method virtual and calling override when trying to override it and that just gets me this error "cannot override inherited member 'MoodyObject.getMood()' because it is not marked virtual, abstract, or override".  I also tried it without the virtual and override and it thinks I'm trying to hide the base method.  Again, I'm new to OOP and would appreciate any guidance.  EDITED TO ADD:  I found it!  The MoodyObject.cs was only a "solution item" in the solution explorer as opposed to a "ConsoleApplication1" item.  I dragged it down to where it belonged in the solution explorer and voila!  It works now.  I marked Luc's answer below as the answer because he offered the help I needed to get to where I have it resolved... I'm learning so much here.  It's amazing and you guys and girls are crazy smart!
103885
We wrote a small Windows class library that implements extension methods for some standard types (strings initially). I placed this in a library so that any of our projects would be able to make use of it by simply referencing it and adding using XXX.Extensions.  A problem came up when we wanted to use some of these methods in Silverlight. Although all the code was compatible, a Windows library can't be referenced in Silverlight so we created a Silverlight library that had links to the same class files and put compiler directives into the classes to allow different using declarations and namespaces. This worked fine until today when I added a new class to the Windows extensions library and realised that I would have to remember to link the class into the Silverlight library too.  This isn't ideal and I wondered if anyone might have ideas for a better way of sharing extension methods and other helper code between Windows and Silverlight projects.
20825
If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I do that?  For example, if I inherit from the Exception class I want to do something like this:  class MyExceptionClass : Exception {      public MyExceptionClass(string message, string extraInfo)      {          //This is where it's all falling apart          base(message);      } }   Basically what I want is to be able to pass the string message to the base Exception class.
24344
What are the C++ rules for calling the base class constructor from a derived class? For example, I know in Java, you must do it as the first line of the subclass constructor (and if you don't, an implicit call to a no-arg super constructor is assumed - giving you a compile error if that's missing).
66464
I don't think this is possible, but if is then I need it :)  I have a auto-generated proxy file from the wsdl.exe command line tool by Visual Studio 2008.  The proxy output is partial classes. I want to override the default constructor that is generated. I would rather not modify the code since it is auto-generated.  I tried making another partial class and redefining the default constructor, but that doesn't work. I then tried using the override and new keywords, but that doesn't work.  I know I could inherit from the partial class, but that would mean I'd have to change all of our source code to point to the new parent class. I would rather not have to do this.  Any ideas, work arounds, or hacks?   //Auto-generated class namespace MyNamespace {    public partial class MyWebService : System.Web.Services.Protocols.SoapHttpClientProtocol {       public MyWebService() {          string myString = "auto-generated constructor";          //other code...       }    } }  //Manually created class in order to override the default constructor namespace MyNamespace {    public partial class MyWebService : System.Web.Services.Protocols.SoapHttpClientProtocol {       public override MyWebService() { //this doesn't work          string myString = "overridden constructor";          //other code...       }    } }
16897
I want to create an alias for a class name. The following syntax would be perfect: public class LongClassNameOrOneThatContainsVersionsOrDomainSpecificName {    ... }  public class MyName = LongClassNameOrOneThatContainsVersionOrDomainSpecificName;  but it won't compile.  Example Note This example is provided for convenience only. Don't try to solve this particular problem by suggesting changing the design of the entire system. The presence, or lack, of this example doesn't change the original question. Some existing code depends on the presence of a static class: public static class ColorScheme {    ... }  This color scheme is the Outlook 2003 color scheme. i want to introduce an Outlook 2007 color scheme, while retaining the Outlook 2003 color scheme: public static class Outlook2003ColorScheme {    ... }  public static class Outlook2007ColorScheme {    ... }  But i'm still faced with the fact that the code depends on the presence of a static class called ColorScheme. My first thought was to create a ColorScheme class that I will inherit from either Outlook2003 or Outlook2007: public static class ColorScheme : Outlook2007ColorScheme { }  but you cannot inherit from a static class. My next thought was to create the static ColorScheme class, but make Outlook2003ColorScheme and Outlook2007ColorScheme classes non-static. Then a static variable in the static ColorScheme class can point to either &quot;true&quot; color scheme: public static class ColorScheme {     private static CustomColorScheme = new Outlook2007ColorScheme();     ... }  private class CustomColorScheme  {     ... }  private class Outlook2008ColorScheme : CustomColorScheme  {     ... }  private class Outlook2003ColorScheme : CustomColorScheme  {    ... }  but that would require me to convert a class composed entirly of readonly static Colors into overridable properties, and then my ColorScheme class would need to have the 30 different property getters thunk down into the contained object. That's just too much typing. So my next thought was to alias the class: public static ColorScheme = Outlook2007ColorScheme;  But that doesn't compile. How can I alias a static class into another name?  Update: Can someone please add the answer &quot;You cannot do this in C#&quot;, so I can mark that as the accepted answer. Anyone else wanting the answer to the same question will find this question, the accepted answer, and a number of workarounds that might, or might not, be useful. I just want to close this question out.
123261
Is there any way to redefine a class or some of its methods without using typical inheritance? For example: class third_party_library {     function buggy_function() {         return 'bad result';     }     function other_functions(){         return 'blah';     } }  What can I do to replace buggy_function()? Obviously this is what I would like to do class third_party_library redefines third_party_library{     function buggy_function() {         return 'good result';     }     function other_functions(){         return 'blah';     } }  This is my exact dilemma: I updated a third party library that breaks my code. I don't want to modify the library directly, as future updates could break the code again. I'm looking for a seamless way to replace the class method. I've found this  that says it can do it, but I'm wary as it's 4 years old. EDIT: I should have clarified that I cannot rename the class from third_party_library to magical_third_party_library or anything else because of framework limitations. For my purposes, would it be possible to just add a function to the class? I think you can do this in C# with something called a &quot;partial class.&quot;
62585
Given the following example, why do I have to explicitly use the statement b-&gt;A::DoSomething() rather than just b-&gt;DoSomething()?  Shouldn't the compiler's overload resolution figure out which method I'm talking about?  I'm using Microsoft VS 2005. (Note: using virtual doesn't help in this case.)  class A {   public:     int DoSomething() {return 0;}; };  class B : public A {   public:     int DoSomething(int x) {return 1;}; };  int main() {   B* b = new B();   b-&gt;A::DoSomething();    //Why this?   //b-&gt;DoSomething();    //Why not this? (Gives compiler error.)   delete b;   return 0; }
4666
Whats wrong with the following c# code? Compiler reports this error:  Inconsistent accessibility: parameter type 'ClassLibrary1.Interface1' is less accessible than method 'ClassLibrary1.Class1.Class1(ClassLibrary1.Interface1)'  with the following code:  interface Interface1&lt;T&gt; {     bool IsDataValid();     /* Other interfaces */ }  public class Class1&lt;T&gt; {     public Interface1&lt;T&gt; interface1;      public Class1(Interface1&lt;T&gt; interface1)     {         this.interface1 = interface1;     }  }   I've since designed my code differently using inheritence to but if anyone could tell me what the above is wrong I'd greatly appreciate it.
81728
Why is the following C# code not allowed:  public abstract class BaseClass {     public abstract int Bar { get;} }  public class ConcreteClass : BaseClass {     public override int Bar     {         get { return 0; }         set {}     } }      CS0546 'ConcreteClass.Bar.set': cannot override because 'BaseClass.Bar' does not have an overridable set accessor
105038
Is it a good concept to use multiple inheritance or can I do other things instead?
107235
#include&lt;iostream&gt; using namespace std;  class A  {    int a;    int b;    public:    void eat()    {       cout&lt;&lt;"A::eat()"&lt;&lt;endl;    } };  class B: public A {    public:    void eat()    {        cout&lt;&lt;"B::eat()"&lt;&lt;endl;     }  };  class C: public A {     public:    void eat()     {        cout&lt;&lt;"C::eat()"&lt;&lt;endl;     }  };  class D: public B, C {  };  int foo(A *ptr) {  ptr-&gt;eat();  } main() {  D obj; foo(&amp;(obj.B)); //error. How do i call with D's B part.  }   The above foo call is a compile time error.  I want to call foo with obj's B part without using virtual inheritance. How do i do that.   Also, in case of virtual inheritance, why the offset information need to be stored in the vtable. This can be determined at the compile time itself. In the above case, if we pass foo with D's object, at compile time only we can calculate the offset of D's A part.
73206
I have two classes:  public class MyBase {     public virtual void DoMe()     {      } }  public class MyDerived:MyBase {     public override void DoMe()     {         throw  new NotImplementedException();     } }   And I have the following code to instantiate MyDerived:          MyDerived myDerived=new MyDerived();   The thing is how to call DoMe of the base class? If I use myDerived.DoMe(), then the derived method wil be called, resulting in an exception. I tried to cast myDerived to MyBase, yet it is still the derived version of the method that gets called.   Edit: As mentioned in the below comment, I can't change eitehr MyDerived or MyBase because they are not my code.