I just wondering if a base class can call the overridden function from a Derived class?
Here's an example:
//Base Class H class BaseClass { public: BaseClass(); virtual ~BaseClass(); virtual void functionA();
[Code] ....
So basically, when I am creating a new object of Derived class, it will initialize BaseClass and the BaseClass will call functionA but I want it to call the function overridden by Derived class.
I know that if I call newObj->functionA it will call the overridden function. Right now I want the base class to call the overridden function "this->functionA(); in BaseClass" during its initialization. Is it possible to do that?
Basically, I have a base class called MainShop and it has 3 derived classes which are SwordShop, SpellBookShop and BowShop. I want the base class to be able to call a function from one of the derived classes but no matter what i do, it doesn't seem to work!
I have two other derived classes, but its basically the same concept. I have a function in one of the derived classes and i would like to call it from the base class. This is one my derived classes:
I have a class MySeqBuildBlockModule that I am inheriting from: public SeqBuildBlock. Other than constructor and destructor, this class MySeqBuildBlockModule has a method: prep.
class MySeqBuildBlockModule: public SeqBuildBlock { friend class SeqBuildBlockIRns; public: MySeqBuildBlockModule (SBBList* pSBBList0, long TI1_In, long TI2_In)// more arguements in this constructor of derived class : SeqBuildBlock (pSBBList0)
[code]....
I would have like to intiantiate an object "myIRns_3" of a class defined in third party library
SeqBuildBlockIRns myIRns_3(pSBBList2);
and would like to access it from the prep function as:
I tried to instantiate following in either private section or in constructor; but w/o any success:
SeqBuildBlockIRns myIRns_3(pSBBList2);
ERRORS encountered:
When I tried to do it inside the constructor, I get the following errors:
MySBBModule.h(113) : error C2065: 'myIRns_3' : undeclared identifier MySBBModule.h(113) : error C2228: left of '.getEnergyPerRequest' must have class/struct/union type MySBBModule.h(116) : error C2065: 'pSBBList' : undeclared identifier MySBBModule.h(116) : error C2227: left of '->prepSBBAll' must point to class/struct/union
When I tried to do it in private section, I get the following errors:
MySBBModule.h(106) : error C2061: syntax error : identifier 'pSBBList2' MySBBModule.h(113) : error C2228: left of '.getEnergyPerRequest' must have class/struct/union type MySBBModule.h(116) : error C2065: 'pSBBList' : undeclared identifier MySBBModule.h(116) : error C2227: left of '->prepSBBAll' must point to class/struct/union
make a class that you can make only one Object of it.
For example if you have Class A. Let's say you create one object A* a=new A();
Now the next time you, try to create another object. For example:
A* b=new A(); What will happen is that b will get the same object (or reference) as a. In other words hey'll be pointing towards the same place. So basically you'll only have one object of it created. I tried doing it but I couldn't quite make it.
Here is what I tried: (but couldn't complete the exercise)
class God { public: static int num; static God* god;
while writing code i got a question. For example i created a class named as unit.
Think a simple game, and the unit class will belong the units.İf i give the preferences as private one by one, it will be irregular. For a detailed game; height, weight, race, hair preferences, eyes... Strength, dexterity, charisma, intelligence, wisdom, constution... experience, damage, armor...
and should i use struct to group them? And how to can i use struct at the inside of class as private?
class Hallway { private: //--------------------------------------------------------------- // DO_04: Declare a Light array of size MAX_LIGHTS // Hint: look through the methods below to find the name to use // for the array //---------------------------------------------------------------
int numLights; int lights[MAX_LIGHTS];
[Code] .....
I keep getting the error " this.lights[i] is not a struct or class and so you cannot use '.' " on line 34.
How am I supposed to define my lights[] array? I can't modify anything except directly after each comment block.
Im currently working on a class assignment and the pseudo code containing the instructions that I need to complete list:
//-------------------------------------------------------------------------------------------------------------- // CTOR: Point() // // DESCRIPTION // Default constructor. Initializes the point to be at the origin (0, 0) and the color to black = (0, 0, 0). // // PSEUDOCODE // Call Init() and pass 0, 0, 0, 0, and 0 as the parameters. //--------------------------------------------------------------------------------------------------------------
My code for this is:
Point::Point(){ void Init(0, 0, 0, 0, 0); }
The code I wrote for the function Init is here:
Point::Init(int mX, int mY, color mColor){ mX = 0; mY = 0; mColor = pInitColor; }
My problem here is that whenever I try calling this function in the point class, I get an error next to void Init saying incomplete type is not allowed. Also visual studio is telling me that it expects a ')' after my first zero in that line.
i usually use this method for accesing functions in executables, the code is executed from a DLL (always works, except when the function are inside of a class, even tho is public):
.h:
typedef int (*pgObjViewportClose) (OBJECTSTRUCT* gObj); extern pgObjViewportClose gObjViewportClose;
That works, but i can't get it to work if the accesing function is inside of a class, i get Unhandled Exception while trying to access a function inside a class, is there a way to do it?.
I have a program where I roll a die X number of times and need to print how many times it lands on each side. I tried to create an array in the class aDie that increments each time the corresponding number is rolled but when I go to call and print it in the main my out put is 0. I just picked how many times it landed on the side 4 just to see if it works and it doesn't.
#define ADIE_H #include <iostream> #include <vector> #include <cstdlib> #include <ctime> using namespace std; class aDie {
I am writing a program where all work is done in the class methods. Main is used to call the methods. I need to know how to get a loop to work without any variables in main that can be used outside the methods. This is what I have in main:
#include <iostream> #include <string> using namespace std; #include "FerryBoat.h" int main() { //create a constructor for a ferry boat FerryBoat myBoat('B', 20, 'A');
#include <iostream> using namespace std; template <typename T> class max_vector { private: T* elemente; int lungime;
[Code] ....
The purpose of this program is to overload two different operators one inside the class, and the other one outside using friend. The problem is that i get 1 error at the '*' one.
I am trying to input a call by value in the second class. It will not compile with how it is currently and says that the pounds needs to be a different variable. Why is this? Is this close to a call-by-value or am I way off?
#include <iostream>; using namespace std; int main() { int a, b, c, d; cout << "Please enter your weight in Pounds and Ounces ";
if possible i want avoid the '&' when i assign the variable address.(variant2 f=varname;//like you see i don't use the '&') for the moment i just need put the address to Variant pointer. but i receive several errors .
I wanted to add that the template argument is needed because its a "special case" but if that doesn't work what would be the next best way to solve this problem. I want to be able to declare the const size of the array outside the class far removed from it actually. I'm actually going off this page