derived

simulate virtual constructor in c++

Hi, In my application I have to derive some classes from a base one, the problem is that I want to enforce the derived classed to have 3 particular constructor implementation. As c++ don't have virtual pure constructor, it seemed quite desperate (I had to check manually each class implementation to ensure that the particular ctors are i...

Avoid slicing of exception types (C++)

I am designing an exception hierarchy in C++ for my library. The "hierarchy" is 4 classes derived from std::runtime_error. I would like to avoid the slicing problem for the exception classes so made the copy constructors protected. But apparently gcc requires to call the copy constructor when throwing instances of them, so complains abou...

C++ Force Template Parameter

I want this code to be possible. template<typename K, typename T, typename Comparer> class AVLTree { ... void foo() { ... int res = Comparer::compare(key1, key2); ... } ... }; Specifically, I want to force Comparer class to have a static int compare(K key1, K key2) function. I was thinking about using ...

C# : manually reading XML config for derived classes

Suppose I have class CarResource, class RaceCarResource : public CarResource, and class SuperDuperUltraRaceCarResource : public RaceCarResource. I want to be able to load their data using a single method LoadFromXML. How would I go about getting the CarResource:LoadFromXML to load it's data, RaceCarResource to call CarResource:LoadFrom...

C# hiding with members

Hi, in the below example, what would happen? class Base { public int abc = 3; } Class Derived : Base { public int abc = 2; } static void Main() { Derived blah = new Derived(); Console.WriteLine(blah.abc); } I'm sure you would see '2' on your console, but what I'm reading (and seeing) opposes that... Why would you see...

derived class cannot display value of base class variables in C#

I am trying to execute the following code class A { protected int a; protected char b; public void Show() { a=5; MessageBox.Show(""+a); } } class B:A { public void Show() { b='z'; MessageBox...

Identifying derived types from a list of base class objects

This may seem kind of "homework-ish" and/or trivial, but it is for a real business purpose; it's just the easiest way I could think of to explain what I'm conceptually trying to do. Suppose I have an Animal class, and some other classes (Bird, Cat, Kangaroo). Each of these inherits from Animal. Animal might look like this: public cl...

c++: Dynamically choose which subclass to create

Hello, I am new to c++ and i have a question. Lets say we have a base class Base and two derived classes, Derived1 and Derived2. f.e. Derived1 has a constructor taking a integer and Derived2 a constructor taking a boolean. Is it possible to determine at run time (or at compile time) which of those two subclasses to create and assign i...

UIscrollview derived classes

Which are the controls (or classes) derived from UIScrollView? ...

List with different types

Hello =) I'm new at the C# thing.... (.net 3.5) I want a Dictionary to hold two different types of object, one of the type is generic. while iterating through the list, i will call methods like add and clone. I have tried it with a base class and subclasses.... namespace ConsoleApplication1 { class Element{ } class Child1...

Subquery using derived table in Hibernate HQL

I have a Hibernate HQL question. I'd like to write a subquery as a derived table (for performance reasons). Is it possible to do that in HQL? Example: FROM Customer WHERE country.id in (SELECT id FROM (SELECT id FROM Country where type='GREEN') derivedTable) (btw, this is just a sample query so don't give advices on rewriting it, is j...

Reference inherited class's <T>ype in a derived class

I don't know if its possible or not, but here's what I need. I'm toying around with something and want to know if its possible since you can't create your own data type based on a sealed type such as int, Int32, Int64, etc. I want to create a top-level class that is defined of a given type with some common stuff. Then, derive this into...

derived class as default argument g++

Please take a look at this code: template<class T> class A { class base { }; class derived : public A<T>::base { }; public: int f(typename A<T>::base& arg = typename A<T>::derived()) { return 0; } }; int main() { A<int> a; a.f(); return 0; } Compiling generates the following error message in g++: test.cpp: In func...

Cast MyEntity To LinqEntity throw a base controller class

hi there i design a multilayer we appliction andusing LINQ a my data provider i need to user my own Entites instead o LINQ etities. so i created Entities Project and create my entities in it. when i get data from contex and cast them to my entities , everything is ok. but when i want to cast on of my entities to linq entity , an excepti...

C# How can I return my base class in a webservice

I have a class Car and a derived SportsCar: Car Something like this: public class Car { public int TopSpeed{ get; set; } } public class SportsCar : Car { public string GirlFriend { get; set; } } I have a webservice with methods returning Cars i.e: [WebMethod] public Car GetCar() { return new Car() { TopSpeed = 100 }...

Any way in C++ for a base class to diallow virtual methods in all derived classes?

Part of our system uses memory shared between processes who do not share a common ancestor. We place C++ objects in this shared memory. Methods on these objects are either inline in the headers or out of line in object libraries that get linked into the respective processes. An error frequently made by new comers to the system is to i...

Flex webcontent derived resources

I have a flex project that is also a web project. It is currently compiling all the mxml files and placing the swf files in the webcontent folder. The problem is that during the build process the webcontent folder gets marked as 'derived', so any files that are in that folder are not by default searchable unless you click the 'derived'...

HSQLDB 1.8 not able to do order by in derived tables?

Hi, I have a query where I am doing an Order by inside of a derived table that is being inner joined. Ex: SELECT g.* FROM ( SELECT ... FROM ... ORDER BY alias.some_column LIMIT 0, 20 ) as g ... # other joins This works fine in MySQL, but it fails in HSQLDB. The reason I put the order by here is that mysql is much fa...

Why do I get derived folders after maven check out in Eclipse.

Every time I check out my project from svn in eclipse and then enable maven dependency management I get some derived folders which happen to be some of the source folders. This kind of folder prevents me from making any modification on the files inside the folders. The derived folders seem to be those that have individual pom.xml file in...

C# XML serialization of derived classes

Hi I am trying to serialize an array of objects which are derived from a class and I keep hitting the same error using c#. Any help is much appreciated. obviously this example has been scaled down for the purpose of this post in the real world Shape would contain a plethora of different shapes. Program.cs namespace XMLInheritTests { ...