Search Results

Search found 1275 results on 51 pages for 'derived'.

Page 1/51 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • derived class as default argument g++

    - by Vincent
    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 function 'int main()': test.cpp:25: error: default argument for parameter of type 'A<int>::base&' has type 'A<int>::derived' The basic idea (using derived class as default value for base-reference-type argument) works in visual studio, but not in g++. I have to publish my code to the university server where they compile it with gcc. What can I do? Is there something I am missing?

    Read the article

  • Subquery using derived table in Hibernate HQL

    - by Vladimir
    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 just the derived table concept I'm interested in) Thanks.

    Read the article

  • c++ casting base class to derived class mess

    - by alan2here
    If I were to create a base class called base and derived classes called derived_1, derived_2 etc... I use a collection of instances of the base class, then when I retrieved an element and tried to use it I would find that C++ thinks it's type is that of the base class, probably because I retrieved it from a std::vector of base. Which is a problem when I want to use features that only exist for the specific derived class who's type I knew this object was when I put it into the vector. So I cast the element into the type it is supposed to be and found this wouldn't work. (derived_3)obj_to_be_fixed; And remembered that it's a pointer thing. After some tweaking this now worked. *((derived_3*)&obj_to_be_fixed); Is this right or is there for example an abc_cast() function that does it with less mess?

    Read the article

  • C# "Rename" Property in Derived Class

    - by Eric
    When you read this you'll be awfully tempted to give advice like "this is a bad idea for the following reason..." Bear with me. I know there are other ways to approach this. This question should be considered trivia. Lets say you have a class "Transaction" that has properties common to all transactions such as Invoice, Purchase Order, and Sales Receipt. Let's take the simple example of Transaction "Amount", which is the most important monetary amount for a given transaction. public class Transaction { public double Amount { get; set; } public TxnTypeEnum TransactionType { get; set; } } This Amount may have a more specific name in a derived type... at least in the real world. For example, the following values are all actually the same thing: Transaction - Amount Invoice - Subtotal PurchaseOrder - Total Sales Receipt - Amount So now I want a derived class "Invoice" that has a Subtotal rather than the generically-named Amount. Ideally both of the following would be true: In an instance of Transaction, the Amount property would be visible. In an instance of Invoice, the Amount property would be hidden, but the Subtotal property would refer to it internally. Invoice looks like this: public class Invoice : Transaction { new private double? Amount { get { return base.Amount; } set { base.Amount = value; } } // This property should hide the generic property "Amount" on Transaction public double? SubTotal { get { return Amount; } set { Amount = value; } } public double RemainingBalance { get; set; } } But of course Transaction.Amount is still visible on any instance of Invoice. Thanks for taking a look!

    Read the article

  • Why do pure virtual base classes get direct access to static data members while derived instances do

    - by Shamster
    I've created a simple pair of classes. One is pure virtual with a static data member, and the other is derived from the base, as follows: #include <iostream> template <class T> class Base { public: Base (const T _member) { member = _member; } static T member; virtual void Print () const = 0; }; template <class T> T Base<T>::member; template <class T> void Base<T>::Print () const { std::cout << "Base: " << member << std::endl; } template <class T> class Derived : public Base<T> { public: Derived (const T _member) : Base<T>(_member) { } virtual void Print () const { std::cout << "Derived: " << this->member << std::endl; } }; I've found from this relationship that when I need access to the static data member in the base class, I can call it with direct access as if it were a regular, non-static class member. i.e. - the Base::Print() method does not require a this- modifier. However, the derived class does require the this-member indirect access syntax. I don't understand why this is. Both class methods are accessing the same static data, so why does the derived class need further specification? A simple call to test it is: int main () { Derived<double> dd (7.0); dd.Print(); return 0; } which prints the expected "Derived: 7"

    Read the article

  • Limited options for accessing events in derived classes?

    - by maxp
    Im refactoring a class, and moving sections into a base class. I have a few events similar to public event EventHandler GridBinding; Which are now in the base class, but i am finding i cannot now check to see if the event is null in my derived class. Doing so gives me the error: The event 'xyz.GridBinding' can only appear on the left hand side of += or -= (except when used from within the type 'xyz._MyBaseClass'). Is this correct, am i missing anything, or is there any way to get around this or is writing an accessor the only way to do this? I am using c#/.net 4.0

    Read the article

  • Base class -> Derived class and vice-versa conversions in C++

    - by Ivan Nikolaev
    Hi! I have the following example code: #include <iostream> #include <string> using namespace std; class Event { public: string type; string source; }; class KeyEvent : public Event { public: string key; string modifier; }; class MouseEvent : public Event { public: string button; int x; int y; }; void handleEvent(KeyEvent e) { if(e.key == "ENTER") cout << "Hello world! The Enter key was pressed ;)" << endl; } Event generateEvent() { KeyEvent e; e.type = "KEYBOARD_EVENT"; e.source = "Keyboard0"; e.key = "SPACEBAR"; e.modifier = "none"; return e; } int main() { KeyEvent e = generateEvent(); return 0; } I can't compile it, G++ throws an error of kind: main.cpp: In function 'int main()': main.cpp:47:29: error: conversion from 'Event' to non-scalar type 'KeyEvent' requested I know that the error is obvious for C++ guru's, but I can't understand why I can't do the conversion from base class object to derived one. Can someone suggest me the solution of the problem that I have? Thx in advice

    Read the article

  • Calling a method with an instance of derived class of derived generic type

    - by madsbirk
    Okay, so I have classes class B<T> : A<T> class L : K and a method void Method(A<K> a) {...} What I would like to do is this b = new B<L>(); Method(b); //error But it is not possible to b to the correct type. Indeed it is not possible to make this cast A<K> t = new A<L>(); //error I would really like to not have to change the internals of Method. I have no problems making changes to B and/or L. Do I have any options for making some sort of workaround? I guess it should be possible for Method to execute all of its method calls etc. on b, since B derives from A and L derives from K?

    Read the article

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

    - by DRapp
    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 two subclasses, but in this case, each class is based on either and int or Int64 type. From THAT instance, create an instance of either one and know its yped basis for parameter referenc / return settings. So when I need to create an instance of the "ThisClass", I don't have to know its type basis of either int or Int64, yet IT will know the type and be able to allow methods/functions to be called with the typed... This way, If I want to change my ThisClass definition from SubLevel1 to SubLevel2, I don't have to dance around all different data type definitions. Hope this makes sense.. public class TopLevel<T> { ... } pubic class SubLevel1 : TopLevel<int> { ... } public class SubLevel2 : TopLevel<Int64> { ... } public class ThisClass : SubLevel1 { ... public <based on the Int data type from SubLevel1> SomeFunc() { return <the Int value computed>; } }

    Read the article

  • Passing Derived Class Instances as void* to Generic Callbacks in C++

    - by Matthew Iselin
    This is a bit of an involved problem, so I'll do the best I can to explain what's going on. If I miss something, please tell me so I can clarify. We have a callback system where on one side a module or application provides a "Service" and clients can perform actions with this Service (A very rudimentary IPC, basically). For future reference let's say we have some definitions like so: typedef int (*callback)(void*); // This is NOT in our code, but makes explaining easier. installCallback(string serviceName, callback cb); // Really handled by a proper management system sendMessage(string serviceName, void* arg); // arg = value to pass to callback This works fine for basic types such as structs or builtins. We have an MI structure a bit like this: Device <- Disk <- MyDiskProvider class Disk : public virtual Device class MyDiskProvider : public Disk The provider may be anything from a hardware driver to a bit of glue that handles disk images. The point is that classes inherit Disk. We have a "service" which is to be notified of all new Disks in the system, and this is where things unravel: void diskHandler(void *p) { Disk *pDisk = reinterpret_cast<Disk*>(p); // Uh oh! // Remainder is not important } SomeDiskProvider::initialise() { // Probe hardware, whatever... // Tell the disk system we're here! sendMessage("disk-handler", reinterpret_cast<void*>(this)); // Uh oh! } The problem is, SomeDiskProvider inherits Disk, but the callback handler can't receive that type (as the callback function pointer must be generic). Could RTTI and templates help here? Any suggestions would be greatly appreciated.

    Read the article

  • Why can I derived from a templated/generic class based on that type in C# / C++

    - by stusmith
    Title probably doesn't make a lot of sense, so I'll start with some code: class Foo : public std::vector<Foo> { }; ... Foo f; f.push_back( Foo() ); Why is this allowed by the compiler? My brain is melting at this stage, so can anyone explain whether there are any reasons you would want to do this? Unfortunately I've just seen a similar pattern in some production C# code and wondered why anyone would use this pattern.

    Read the article

  • Extract derived 3D scaling from a 3D Sprite to set to a 2D billboard

    - by Bill Kotsias
    I am trying to get the derived position and scaling of a 3D Sprite and set them to a 2D Sprite. I have managed to do the first part like this: var p:Point = sprite3d.local3DToGlobal(new Vector3D(0,0,0)); billboard.x = p.x; billboard.y = p.y; But I can't get the scaling part correctly. I am trying this: var mat:Matrix3D = sprite3d.transform.getRelativeMatrix3D(stage); // get derived matrix(?) var scaleV:Vector3D = mat.decompose()[2]; // get scaling vector from derived matrix var scale:Number = scaleV.length; billboard.scaleX = scale; billboard.scaleY = scale; ...but the result is apparently wrong. PS. One might ask what I am trying to achieve. I am trying to create "billboard" 3D sprites, i.e. sprites which are affected by all 3D transformations except rotations, thus they always face the "camera".

    Read the article

  • Statically Init a derived class

    - by AC
    With c++, Is there a way to get a derived class to inherit its own static initializer? I am trying to do something like the following: class Base { public: class StaticInit { public: virtual StaticInit() =0; }; }; class Derived: public Base { public: virtual StaticInit::StaticInit() { //do something with the derived class } static StaticInit init; } static Derived::StaticInit init; it would also be nice if I didn't have to define the init var in each derived class. I am currently redefining the StaticInit internal class in each derived class but it seems redundant. Each derived class is a singleton, and I need the instance to be stored in a lookup table at program startup.

    Read the article

  • base pointer to derived class

    - by Jay
    Suppose there are Base class and Derived class. Base *A = new Base; Here A is a pointer point to Base class, and new constructs one that A points to. I also saw Base *B = new Derived; How to explain this? B is a pointer to Base Class, and a Derived class constructed and pointed by B? If there is a function derived from Base class, say, Virtual void f(), and it's been overridden in Derived class, then B->f() will invoke which version of the function? version in Base class, or version that overridden in Derived Class. What if there is a new function void g()in Derived, is B->g() going to invoke this function properly? One more is, is int *a = new double; or int *a = new int; legal?

    Read the article

  • ReSharper: find derived types constructor usages points

    - by Roman
    I have some base class ControlBase and many derived classes which also have derived classes... ControlBase and derived classes have parameterless constructor. How can I easily find all derived classes constructor invocation points? ReSharper find usages on ControlBase constructor shows only usages of this base class constructor but not derived classes constructors. Thanks.

    Read the article

  • How do you make a Factory that can return derived types?

    - by Seth Spearman
    I have created a factory class called AlarmFactory as such... 1 class AlarmFactory 2 { 3 public static Alarm GetAlarm(AlarmTypes alarmType) //factory ensures that correct alarm is returned and right func pointer for trigger creator. 4 { 5 switch (alarmType) 6 { 7 case AlarmTypes.Heartbeat: 8 HeartbeatAlarm alarm = HeartbeatAlarm.GetAlarm(); 9 alarm.CreateTriggerFunction = QuartzAlarmScheduler.CreateMinutelyTrigger; 10 return alarm; 11 12 break; 13 default: 14 15 break; 16 } 17 } 18 } Heartbeat alarm is derived from Alarm. I am getting a compile error "cannot implicitly convert type...An explicit conversion exists (are you missing a cast?)". How do I set this up to return a derived type? Seth

    Read the article

  • Why is 'virtual' optional for overridden methods in derived classes?

    - by squelart
    When a method is declared as virtual in a class, its overrides in derived classes are automatically considered virtual as well, and the C++ language makes this keyword virtual optional in this case: class Base { virtual void f(); }; class Derived : public Base { void f(); // 'virtual' is optional but implied. }; My question is: What is the rationale for making virtual optional? I know that it is not absolutely necessary for the compiler to be told that, but I would think that developers would benefit if such a constraint was enforced by the compiler. E.g., sometimes when I read others' code I wonder if a method is virtual and I have to track down its superclasses to determine that. And some coding standards (Google) make it a 'must' to put the virtual keyword in all subclasses.

    Read the article

  • cast operator to base class within a thin wrapper derived class

    - by miked
    I have a derived class that's a very thin wrapper around a base class. Basically, I have a class that has two ways that it can be compared depending on how you interpret it so I created a new class that derives from the base class and only has new constructors (that just delegate to the base class) and a new operator==. What I'd like to do is overload the operator Base&() in the Derived class so in cases where I need to interpret it as the Base. For example: class Base { Base(stuff); Base(const Base& that); bool operator==(Base& rhs); //typical equality test }; class Derived : public Base { Derived(stuff) : Base(stuff) {}; Derived(const Base& that) : Base(that) {}; Derived(const Derived& that) : Base(that) {}; bool operator==(Derived& rhs); //special case equality test operator Base&() { return (Base&)*this; //Is this OK? It seems wrong to me. } }; If you want a simple example of what I'm trying to do, pretend I had a String class and String==String is the typical character by character comparison. But I created a new class CaseInsensitiveString that did a case insensitive compare on CaseInsensitiveString==CaseInsensitiveString but in all other cases just behaved like a String. it doesn't even have any new data members, just an overloaded operator==. (Please, don't tell me to use std::string, this is just an example!) Am I going about this right? Something seems fishy, but I can't put my finger on it.

    Read the article

  • SQL Server Integration Services 2008: Importing Excel Data Using Derived Column Transformation

    The complexity involved in transferring data between Excel and SQL Server results from different and sometimes incompatible data types. The Import and Export wizard mitigates potential issues introduced by these incompatibilities by taking advantage of Data Conversion Transformation. Marcin Policht describes another approach that produces an equivalent outcome by employing Derived Column Transformation instead.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >