base-class

GCC issue: using a member of a base class that depends on a template argument

坚强是说给别人听的谎言 提交于 2019-11-26 14:40:22
The following code doesn't compile with gcc, but does with Visual Studio: template <typename T> class A { public: T foo; }; template <typename T> class B: public A <T> { public: void bar() { cout << foo << endl; } }; I get the error: test.cpp: In member function ‘void B::bar()’: test.cpp:11: error: ‘foo’ was not declared in this scope But it should be! If I change bar to void bar() { cout << this->foo << endl; } then it does compile, but I don't think I have to do this. Is there something in the official specs of C++ that GCC is following here, or is it just a quirk? This changed in gcc-3.4 .

How to hide an inherited property in a class without modifying the inherited class (base class)?

点点圈 提交于 2019-11-26 08:26:49
问题 If i have the following code example: public class ClassBase { public int ID { get; set; } public string Name { get; set; } } public class ClassA : ClassBase { public int JustNumber { get; set; } public ClassA() { this.ID = 0; this.Name = string.Empty; this.JustNumber = string.Empty; } } What should I do to hide the property Name (Don\'t shown as a member of ClassA members) without modifying ClassBase ? 回答1: I smell a code smell here. It is my opinion that you should only inherit a base class

Does delete on a pointer to a subclass call the base class destructor?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 06:53:13
问题 I have an class A which uses a heap memory allocation for one of its fields. Class A is instantiated and stored as a pointer field in another class ( class B . When I\'m done with an object of class B, I call delete , which I assume calls the destructor... But does this call the destructor of class A as well? Edit: From the answers, I take that (please edit if incorrect): delete of an instance of B calls B::~B(); which calls A::~A(); A::~A should explicitly delete all heap-allocated member

GCC issue: using a member of a base class that depends on a template argument

倖福魔咒の 提交于 2019-11-26 03:58:53
问题 The following code doesn\'t compile with gcc, but does with Visual Studio: template <typename T> class A { public: T foo; }; template <typename T> class B: public A <T> { public: void bar() { cout << foo << endl; } }; I get the error: test.cpp: In member function ‘void B::bar()’: test.cpp:11: error: ‘foo’ was not declared in this scope But it should be! If I change bar to void bar() { cout << this->foo << endl; } then it does compile, but I don\'t think I have to do this. Is there something

Cast base class to derived class python (or more pythonic way of extending classes)

心不动则不痛 提交于 2019-11-26 03:54:40
问题 I need to extend the Networkx python package and add a few methods to the Graph class for my particular need The way I thought about doing this is simplying deriving a new class say NewGraph , and adding the required methods. However there are several other functions in networkx which create and return Graph objects (e.g. generate a random graph). I now need to turn these Graph objects into NewGraph objects so that I can use my new methods. What is the best way of doing this? Or should I be

What are good candidates for base controller class in ASP.NET MVC?

北城以北 提交于 2019-11-26 01:47:15
问题 I\'ve seen a lot of people talk about using base controllers in their ASP.NET MVC projects. The typical examples I\'ve seen do this for logging or maybe CRUD scaffolding. What are some other good uses of a base controller class? 回答1: There are no good uses of a base controller class. Now hear me out. Asp.Net MVC, especially MVC 3 has tons of extensibility hooks that provide a more decoupled way to add functionality to all controllers. Since your controllers classes are very important and

Is it possible to assign a base class object to a derived class reference with an explicit typecast?

会有一股神秘感。 提交于 2019-11-26 01:36:29
问题 Is it possible to assign a base class object to a derived class reference with an explicit typecast in C#?. I have tried it and it creates a run-time error. 回答1: No. A reference to a derived class must actually refer to an instance of the derived class (or null). Otherwise how would you expect it to behave? For example: object o = new object(); string s = (string) o; int i = s.Length; // What can this sensibly do? If you want to be able to convert an instance of the base type to the derived

Interface vs Base class

六眼飞鱼酱① 提交于 2019-11-25 23:56:57
问题 When should I use an interface and when should I use a base class? Should it always be an interface if I don\'t want to actually define a base implementation of the methods? If I have a Dog and Cat class. Why would I want to implement IPet instead of PetBase? I can understand having interfaces for ISheds or IBarks (IMakesNoise?), because those can be placed on a pet by pet basis, but I don\'t understand which to use for a generic Pet. 回答1: Let's take your example of a Dog and a Cat class, and

Creating a singleton in Python

限于喜欢 提交于 2019-11-25 22:19:33
问题 This question is not for the discussion of whether or not the singleton design pattern is desirable, is an anti-pattern, or for any religious wars, but to discuss how this pattern is best implemented in Python in such a way that is most pythonic. In this instance I define \'most pythonic\' to mean that it follows the \'principle of least astonishment\' . I have multiple classes which would become singletons (my use-case is for a logger, but this is not important). I do not wish to clutter

What are good candidates for base controller class in ASP.NET MVC?

时光怂恿深爱的人放手 提交于 2019-11-25 21:51:45
I've seen a lot of people talk about using base controllers in their ASP.NET MVC projects. The typical examples I've seen do this for logging or maybe CRUD scaffolding. What are some other good uses of a base controller class? John Farrell There are no good uses of a base controller class. Now hear me out. Asp.Net MVC, especially MVC 3 has tons of extensibility hooks that provide a more decoupled way to add functionality to all controllers. Since your controllers classes are very important and central to an application its really important to keep them light, agile and loosely coupled to