473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

function in the class have addresses

nik
hello friends,
I have a serious problem .i have a base class having 15 member function
and there r 4 classes derived from this base class .the situation is
like if certain condion is met then the particular function get
executed.I have a example following with two classes
// fsmvir.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream.h>
#include "statemachineconst.h"
int a;
class State
{
protected:
int currState;
int currEvent;
public:
int GetdataState() ;
// display the current state from the user
int GetdataEvent() ;
// get the current event from the user
void CurrentStateDisplay(int) ;

int Event1_Handler()
{
return state1;
}
int Event2_Handler()
{
return state2;
}
int Event3_Handler()
{
return state1;
}
virtual void ChangeState()
{
}
};

int State::GetdataState()
{
cout<<"\nEnter the state ";
cin>>currState;
return currState;
}

int State::GetdataEvent()
{
cout<<"\nEnter the event ";
cin>>currEvent;
return currEvent;
}

void State::CurrentStateDisplay(int b)
{
if(b==0)
cout<<"\nERROR";
else
cout<<"\nYOU R IN STATE "<<a;
}
//derived State 1 from the base class State
class State1:public State
{
public:
void ChangeState()
{
switch(GetdataEvent())//certain condition
{
case event1:a=Event1_Handler();
break;
case event2:a=Event2_Handler();
break;
default:
cout<<"\nINVALID STATE ";
a=0;
}
CurrentStateDisplay(a);
}
};
//derived State 2 from the base class State

class State2:public State
{
public:
void ChangeState()
{
switch(GetdataEvent())
{
case event2:a=Event2_Handler();
break;
case event3:a=Event3_Handler();
break;
default:
cout<<"\nINVALID STATE ";
a=0;
}
CurrentStateDisplay(a);

}
};
//main function
int main(int argc, char* argv[])
{

char ch='y';
State *ptr;
State s;
State1 s1;
State2 s2;
ptr=&s;
while(ch=='y')
{
a=1;
switch(ptr->GetdataState())
{
case state1:ptr=&s1;
ptr->ChangeState();
break;
case state2:ptr=&s2;
ptr->ChangeState();
break;
default:cout<<"\nINVALID STATE";
}
cout<<"\nTO CONTINUE PRESS y ";
cin>>ch;
}
return 0;
}
can i have the simpler way to call the member function of the base
class.(i.e by any mathematical relation)

Aug 1 '06 #1
1 1344
[snip]
//main function
int main(int argc, char* argv[])
{

char ch='y';
State *ptr;
State s;
State1 s1;
State2 s2;
ptr=&s;
while(ch=='y')
{
a=1;
switch(ptr->GetdataState())
{
case state1:ptr=&s1;
ptr->ChangeState();
break;
case state2:ptr=&s2;
ptr->ChangeState();
break;
default:cout<<"\nINVALID STATE";
}
cout<<"\nTO CONTINUE PRESS y ";
cin>>ch;
}
return 0;
}
can i have the simpler way to call the member function of the base
class.(i.e by any mathematical relation)
Keep you code as short as possible.

Do you want:

class A
{
void foo() {printf("FooA");}
};

class B : public A
{
void foo() {printf("FooB";}
}

void bar(A* pA)
{
}
// them try:
int main()
{
B b;
bar( (A*) &b);
}

// you don't need the (A*) cast explicitly, though

Aug 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: BadOmen | last post by:
I have made an array in a function in a Class now I need to get to that Array from an other function in an other Class, How do I do that? The Array has no fixed size as it is dependent on how...
4
by: keepyourstupidspam | last post by:
Hello, I have a class X with a member function setConfigValues(). I want to access this member function in another class Y. Y is not inherited from X. A member function of class X called run()...
9
by: kish_nand | last post by:
Could someone please explain me the concept behind virtual functions and vtables. I am little confused about this. Please refer to the following code and tell me how many virtual tables would be...
1
by: Peter Monica | last post by:
I am trying to calculate distance from a point entered by a user usng a function in Access in a query that calls tables in an Oracle database as well as in Access. I am getting the following...
6
by: Rahul K | last post by:
Hi I am working on Visual Studio on Windows. I have a function which return the list of all the IP Addresses of a machine: vector<char *getAllLocalIPAddress() { char localHostName; struct...
4
by: poojak | last post by:
I have write two different js function in a external file. one function write a table (I used innerHTML for this.) and another function is for showing/ hideing some rows depending on radio button...
1
by: David Lozzi | last post by:
Howdy, A little background, using asp.net 2.0, i'm using a wizard object to create a email interface for a user to email out their clientele, about 200 or so, depending on the selection. The...
18
by: WaterWalk | last post by:
Hello. Suppose there is an implementation of C++, in which when a class object is allocated, its member functions are also allocated in addition to its data members. So that every class object has...
1
by: eastlands | last post by:
I need to use an unmanaged c++ dll which uses structs that contain callbacks and also functions. I have included the appropriate c++ definitials and my c# translations below. I first defined the...
6
by: Poke386 | last post by:
I'm in the process of making an text based-rpg in C++. Its just a little project so I can learn some object-oriented programming, nothing serious. My problem is that I've created a class like so: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.