problem about derived-Collection of common programming errors
Wim Coenen
c# variables base derived
class Program {static void Main(string[] args){baseClass obj = new baseClass();obj.intF = 5;obj.intS = 4;child obj1 = new child();Console.WriteLine(Convert.ToString(obj.addNo()));Console.WriteLine(Convert.ToString(obj1.add()));Console.ReadLine();} } public class baseClass {public int intF = 0, intS = 0;public int addNo(){int intReturn = 0;intReturn = intF + intS;return intReturn;} } class child : baseClass {public int add(){int intReturn = 0;intReturn = base.intF * base.intS;return intReturn;} }
JMRC
c++ derived
Is it possible what I’m trying to achieve. This is the problem:class Content{};class Content1 : public Content{}; class Content1_1 : public Content1{}; class Content1_2 : public Content1{};class Content2 : public Content{}; class Content2_1 : public Content2{}; class Content2_2 : public Content2{};class Container{ public:Content* c; };Is it possible to determine if the pointer of the Container class points to an object of Content1 or an object of a class derived from Content1?Thanks.EDIT:If I lo
DRapp
c# class derived
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 bas
Pygmy
c# class methods handler derived
Suppose I have a baseclass called IMessage, and lots of derived message classes.In my program I have one method that receives all messages :void ReceiveMessage(IMessage message) { }and I’d like to call a specific method for each type of message. It would be great if I could do :void ReceiveMessage(IMessage message) {HandleMessage(message); }void HandleMessage(DummyMessage message) {Blah; }void HandleMessage(SillyMessage message) {Yuk; }..but apparently “we ain’t going out like that”.So how would
111111
c# xml class derived
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.csnamespace XMLInheritTests {class Program{static void Main(string[] args){Shape[] a = new Shape[1] { new Square(1) };FileStream fS = new FileStream(“C:\\shape.xml”,FileMode.OpenOrCreate);XmlSeriali
user1395887
c++ polymorphism base runtime.exec derived
I am stuck with a problem of runtime pointer assigning in C++. I have a base class with 2 members thread and threads.class base {struct base_struct {int a;};base_struct thread;std::vector<base_struct> threads;void fn () {}};derived1 is derived from base and has the same two members (thread and threads) but of different type.class derived1 : public base {struct derived_struct11 : public base_struct {int b;};derived_struct11 thread;std::vector<derived_struct11> threads;void fn () {prin
geoyar
c++ derived
Suppose you have base class and several derived classes in your C++ app. You want to enumerate all classes derived from this base without instantiation the derived classes, say to present them to the user in the class name list box. Obviously, the needed information is somewhere in the app. How to retrieve it?
sbi
c++ templates class derived
class A { public:template<typename T> void func(size_t n, T values[]) { … } };class B : public A { public:void func(size_t n, uint32_t values[]) { … } };Why does function B::func() not take precedence over the function template A::func() when calling this code?uint32_t values[5]; A* obj = new B(); obj->func(5, values);
Sosukodo
c++ virtual derived default-parameters
Can someone explain why the result of the code below would be “class B::1” ? Why does the virtual method of derived class uses the default parameter of a base class and not his own? For me this is pretty strange. Thanks in advance!Code:#include <iostream>using namespace std;class A { public:virtual void func(int a = 1){cout << “class A::” << a;} };class B : public A { public:virtual void func(int a = 2){cout << “class B::” << a;} };int main() {A * a = new B;a->fu
Al007
module runtime fortran90 derived
I have a question regarding assigning Fortran90 derived types and pointers at runtime. I want to pass a derived variable type to a subroutine after the code reads an input file. So depending on the input I pass the appropriate data type. Let me explain:I have two modules:Module A_mod and Module B_mod. Each has it’s own unique data type and subroutines. For example:Module A_modtype A real :: x, y end typecontainssubroutine FunA(me) type (A), intent(in) :: me <do stuff> end subroutineEnd mod
John Yates
c++ virtual design-patterns derived
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 introduce a virtual method somewhere. This is guaranteed to crash the system as there is no way to ensure that the VT (virtual table) resides at the same address i
70sCommander
c++ qt virtual derived qobject
I’ve got the following situation in my current project: “collect2: Id returned 1 exit status” returned by the compiler using the following code:#ifndef BASE_02_H #define BASE_02_H#include <QtCore>class Base_02 {public:Base_02();virtual void method()=0; };#endif // BASE_02_H#include “base_02.h” #include <QtCore>Base_02::Base_02() {}//———————————————————————————————————————————-#ifndef DERIVED_02_H #d
LihO
c++ stl pointers vector derived
I’m using a vector of pointers to objects. These objects are derived from a base class, and are being dynamically allocated and stored.For example, I have something like:vector<Enemy*> Enemies;and I’ll be deriving from the Enemy class and then dynamically allocating memory for the derived class, like this:enemies.push_back(new Monster());What are things I need to be aware of to avoid memory leaks and other problems?
Alexander
c++ list inheritance polymorphism derived
I have two classes, one of which inherits the other:class baseClass { public:virtual void show(); };void baseClass::show(){cout << “Base class” << endl;}class derivedClass { public:void show(); };void derivedClass::show(){cout << “Derived class” << endl;}If I make a derivedClass object and called the show function, it correctly prints “Derived class”. If I do the following:derivedClass b; baseClass* b; b=&d; b->show();It again correctly prints out “Derived class”.
Janis
c++ oop copy-constructor derived inherited
Let the example be:class Base {Base (const Base & copyFrom) { globalRegister (* this); } }class Derived {Derived (const Derived & copyFrom) : Base (copyFrom) {} }I’ve read suggestions to include the Base’s copy constructor on the initialisation list of Derived in order to copy over the Base’s properties (as in the example).However, I have the Base’s copy constructor passing itself (* this) to other object (to be registered with that object). Would that be a case where I actually must use
user1757550
class base derived
I have a vague idea of why this isn’t allowed, but I’m looking for something more concrete. I’m assuming it has something to do with the fact that all of the methods in a base class might not necessarily be virtual.Can anyone help me out?
marc_s
sql table alias derived
This is the problematic part of my query:SELECT(SELECT id FROM users WHERE name = ‘John’) as competitor_id,(SELECT MIN(duration)FROM(SELECT duration FROM attemptsWHERE userid=competitor_id ORDER BY created DESC LIMIT 1,1) x) as best_timeOn execution, it throws this error:1054 – Unknown column ‘competitor_id’ in ‘where clause’It looks like the derived table ‘x’ can’t see the parent’s query alias competitor_id. Is there any way how to create some kind of global alias, which will be usable by all d
Web site is in building