inheritance

Create a superclass from multiple classes that have common members [closed]

删除回忆录丶 提交于 2020-01-13 14:56:04
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I've had this a number of times now. In longer running software projects two or three classes are totally different at the outset. However, as time goes by requirements change, users get a bit smarter, on rare occasions I even get a bit smarter and two seemingly different processes turn out to be very similar.

Can I tell which template instance class(es) my class is inheriting from?

倖福魔咒の 提交于 2020-01-13 13:52:09
问题 Given this code: template < int I > class Foo { public: int v; Foo() { v = I; } virtual ~Foo() {} }; class Bar : public Foo<0>, public Foo<3> { public: template < int I > int getValue() { return Foo<I>::v; } }; int main() { Bar b; cout << b.getValue<0>() << endl; // prints 0 cout << b.getValue<3>() << endl; // prints 3 cout << b.getValue<4>() << endl; // compiler error return 0; } Is it possible to iterate over all Foo<i> classes from which Bar inherits? We can assume that i is between 0 and

Can I tell which template instance class(es) my class is inheriting from?

℡╲_俬逩灬. 提交于 2020-01-13 13:51:12
问题 Given this code: template < int I > class Foo { public: int v; Foo() { v = I; } virtual ~Foo() {} }; class Bar : public Foo<0>, public Foo<3> { public: template < int I > int getValue() { return Foo<I>::v; } }; int main() { Bar b; cout << b.getValue<0>() << endl; // prints 0 cout << b.getValue<3>() << endl; // prints 3 cout << b.getValue<4>() << endl; // compiler error return 0; } Is it possible to iterate over all Foo<i> classes from which Bar inherits? We can assume that i is between 0 and

How to hide extension methods from derived classes?

北慕城南 提交于 2020-01-13 11:52:52
问题 I have a base abstract class to implement template method pattern. public abstract class OptionalParameter { //Template Method Pattern public string GenerateQueryString() { return this.GenerateQueryStringWithParameters(); } } And I have an extension method for all OptionalParameter type. public static class OptionalParameterExtensions { public static string GenerateQueryStringWithParameters(this OptionalParameter optionalParameters) { } } I inherited a class from OptionalParameter named

How to hide extension methods from derived classes?

爱⌒轻易说出口 提交于 2020-01-13 11:51:40
问题 I have a base abstract class to implement template method pattern. public abstract class OptionalParameter { //Template Method Pattern public string GenerateQueryString() { return this.GenerateQueryStringWithParameters(); } } And I have an extension method for all OptionalParameter type. public static class OptionalParameterExtensions { public static string GenerateQueryStringWithParameters(this OptionalParameter optionalParameters) { } } I inherited a class from OptionalParameter named

How to hide extension methods from derived classes?

江枫思渺然 提交于 2020-01-13 11:51:09
问题 I have a base abstract class to implement template method pattern. public abstract class OptionalParameter { //Template Method Pattern public string GenerateQueryString() { return this.GenerateQueryStringWithParameters(); } } And I have an extension method for all OptionalParameter type. public static class OptionalParameterExtensions { public static string GenerateQueryStringWithParameters(this OptionalParameter optionalParameters) { } } I inherited a class from OptionalParameter named

Use new keyword in c# [duplicate]

扶醉桌前 提交于 2020-01-13 09:29:21
问题 This question already has answers here : new keyword in method signature (8 answers) Closed 6 years ago . I have two classes class A { public virtual void Metod1() { Console.WriteLine("A.Method1"); } } class B : A { public new void Metod1() { Console.WriteLine("B.Method1"); } } Then I write some code that declares instances of these classes, and calls their methods static void Main(string[] args) { A a = new B(); a.Metod1(); B b = new B(); b.Metod1(); Console.ReadKey(); } I gave following

LINQ .Include() properties from sub-types in TPH inheritance

这一生的挚爱 提交于 2020-01-13 09:15:32
问题 I am using table-per-hierarchy (TPH) inheritance in Entity Framework. Now I am looking to get a list of - in this example - Departments where departments can be a sub-type. I'd like the items in the collection to include their own custom properties and not only the Base Model's properties. How can I achieve this? public class Department { public Department() { DepartmentType = this.GetType.Name; } public int Id {get; set;} public string DepartmentType {get; set;} } public class Finance :

Private inheritance and implicit conversion

浪尽此生 提交于 2020-01-13 09:13:21
问题 I have a class that inherits privately from std::string , and adds some functions. I want to be able to use this class just like std::string , so I am trying to define an implicit conversion operator ( operator string() ). However, I keep getting inaccessible base error. #include <iostream> #include <string> using namespace std; class Test:private string { int _a; public: operator string() { return "hello"; } }; int main() { Test t; if(t == "hello") { cout<<"world\n"; } } Error: trial.cpp: In

Private inheritance and implicit conversion

最后都变了- 提交于 2020-01-13 09:13:16
问题 I have a class that inherits privately from std::string , and adds some functions. I want to be able to use this class just like std::string , so I am trying to define an implicit conversion operator ( operator string() ). However, I keep getting inaccessible base error. #include <iostream> #include <string> using namespace std; class Test:private string { int _a; public: operator string() { return "hello"; } }; int main() { Test t; if(t == "hello") { cout<<"world\n"; } } Error: trial.cpp: In