base-class

ASP.NET MVC: Ignore custom attribute in a base controller class

时光毁灭记忆、已成空白 提交于 2019-11-29 04:59:23
I have a number of Controllers in my project that all inherit from a controller I've named BaseController. I wrote a custom attribute that I applied to the entire BaseController class, so that each time an action runs in any of my controllers, that attribute will run first. The problem is that I have a couple of controller actions that I'd like to ignore that attribute, but I don't know how to do it. Can anyone help? I'm using MVC 1. Thanks. I had a similar need for something like this and found that by creating an authorization filter (implementing/deriving from FilterAttribute,

How to resolve “pure virtual method called”

拈花ヽ惹草 提交于 2019-11-28 20:33:43
I understand why this is happening, but I'm stuck trying to resolve it...here is what my code is doing when the error is generated (thus, leading to a crash) when my program exits... pure virtual method called SomeClass::~SomeClass() { BaseClassObject->SomePureVirtualMethod(this); } void DerivedClass::SomePureVirtualMethod(SomeClass* obj) { //Do stuff to remove obj from a collection } I never have a call to new SomeClass but I have a QList<SomeClass*> which I append SomeClass* objects to. The purpose of this destructor in SomeClass is to tell DerivedClass to remove a specific instance of

Why use base class pointers for derived classes

徘徊边缘 提交于 2019-11-28 14:54:51
问题 class base{ ..... virtual void function1(); virtual void function2(); }; class derived::public base{ int function1(); int function2(); }; int main() { derived d; base *b = &d; int k = b->function1() // Why use this instead of the following line? int k = d.function1(); // With this, the need for virtual functions is gone, right? } I am not a CompSci engineer and I would like to know this. Why use virtual functions if we can avoid base class pointers? 回答1: The power of polymorphism isn't really

C# protected members accessed via base class variable [duplicate]

时光毁灭记忆、已成空白 提交于 2019-11-28 07:13:15
问题 This question already has an answer here: Why can't I access C# protected members except like this? 7 answers It may seems rather newbie question, but can you explain why method Der.B() cannot access protected Foo via Base class variable? This looks weird to me: public class Base { protected int Foo; } public class Der : Base { private void B(Base b) { Foo = b.Foo; } // Error: Cannot access protected member private void D(Der d) { Foo = d.Foo; } // OK } Thanks! 回答1: This is a frequently asked

How to call an explicitly implemented interface-method on the base class

吃可爱长大的小学妹 提交于 2019-11-28 06:47:32
I have a situation, where two classes (one deriving from the other) both implement the same interface explicitly: interface I { int M(); } class A : I { int I.M() { return 1; } } class B : A, I { int I.M() { return 2; } } From the derived class' implementation of I.M() , I'd like to call the implementation of the base class, but I don't see how to do it. What I tried so far is this (in class B): int I.M() { return (base as I).M() + 2; } // this gives a compile-time error //error CS0175: Use of keyword 'base' is not valid in this context int I.M() { return ((this as A) as I).M() + 2; } // this

C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass

耗尽温柔 提交于 2019-11-28 03:31:14
What is the recommended approach to naming base classes? Is it prefixing the type name with " Base " or " Abstract " or would we just suffix it with "Base"? Consider the following: type: ViewModel e.g. MainViewModel , ReportViewModel base class: BaseViewModel or ViewModelBase or AbstractViewModel Also consider: type: Product e.g. VirtualProduct , ExpiringProduct base class: BaseProduct or ProductBase or AbstractProduct Which do you think is more standard? class Entity : EntityBase { } or class Entity : BaseEntity { } Joe There are examples in the Framework with the Base suffix, e.g. System

Base template class data members are not visible in derived template class?

女生的网名这么多〃 提交于 2019-11-28 01:12:36
Consider the following C++ code, template <typename Derived> struct A { bool usable_; }; template <typename Derived> struct B : A< B<Derived> > { void foo() { usable_ = false; } }; struct C : B<C> { void foo() { usable_ = true; } }; int main() { C c; } I got compilation error: In member function void B<Derived>::foo() : template_inherit.cpp:12: error: 'usable_' was not declared in this scope. Why is that ? Any good fix ? That's because usable_ is a non-dependent name, so it is looked up at the time the template is parsed, instead of being looked up at instantiation (when the base class is

Why does the compiler select the base class constructor inside the template argument list?

守給你的承諾、 提交于 2019-11-27 23:35:09
问题 Follow-up question to this one. Basically, in the following code, why does the compiler think that the B inside A<B> in C s constructor refer to the (inaccessible) constructor of the B base class? struct B{}; template <typename T> struct A : private T{}; struct C : public A<B>{ C(A<B>); // ERROR HERE }; Live example on Ideone. Output: prog.cpp:1:9: error: 'struct B B::B' is inaccessible prog.cpp:7:7: error: within this context Note that the same error pops up if you change the constructor

Will the base class constructor be automatically called?

核能气质少年 提交于 2019-11-27 17:25:30
class Person { public int age; public Person() { age = 1; } } class Customer : Person { public Customer() { age += 1; } } Customer customer = new Customer(); Would the age of customer be 2? It seems like the base class's constructor will be called no matter what. If so, why do we need to call base at the end sometimes? public Customer() : base() { ............. } This is simply how C# is going to work. The constructors for each type in the type hierarchy will be called in the order of Most Base -> Most Derived. So in your particular instance, it calls Person() , and then Customer() in the

Order of calling base class constructor from derived class initialization list

爱⌒轻易说出口 提交于 2019-11-27 14:47:16
struct B { int b1, b2; B(int, int); }; struct D : B { int d1, d2; // which is technically better ? D (int i, int j, int k, int l) : B(i,j), d1(k), d2(l) {} // 1st Base // or D (int i, int j, int k, int l) : d1(k), d2(l), B(i,j) {} // last Base }; Above is just pseudo code. In actual I wanted to know that does the order of calling base constructor matter ? Are there any bad behaviors (especially corner cases ) caused by any of the cases ? My question is on more technical aspect and not on coding styles. AnT The order you refer in your question is not the "order of calling base constructor". In