Hi guys,
I know function pointers but I'm having a hard time about callback function when it is associated with abstract class. I have an example code below which I got from a book. Kindly explain it to me and how will can I called and implement the callback function.
ImageReader.h
class MImageReadyCallBack
{
public:
virtual void ImageReadyL(const TInt& aError) = 0;
};
class CImage_Reader : public CActive
{
public:
CImage_Reader(MImageReadyCallBack& aNotify);
}
In this example, how can will I implement int the .cpp the CImage_Reader constructor since it needs a callback function of type MImageReadyCallBack?Where will I implement the ImageReadyL functions? Do I need to inherit MImageReadyCallBack in the declaration of CImage_Reader class?
Hope you can explain it to me. I will try to research while waiting on your reply. Thank you guys...
5 4759
Hi guys,
I know function pointers but I'm having a hard time about callback function when it is associated with abstract class. I have an example code below which I got from a book. Kindly explain it to me and how will can I called and implement the callback function.
ImageReader.h
class MImageReadyCallBack
{
public:
virtual void ImageReadyL(const TInt& aError) = 0;
};
class CImage_Reader : public CActive
{
public:
CImage_Reader(MImageReadyCallBack& aNotify);
}
In this example, how can will I implement int the .cpp the CImage_Reader constructor since it needs a callback function of type MImageReadyCallBack?Where will I implement the ImageReadyL functions? Do I need to inherit MImageReadyCallBack in the declaration of CImage_Reader class?
Hope you can explain it to me. I will try to research while waiting on your reply. Thank you guys...
Hi,
The virtual concept works like this. -
class A
-
{
-
public:
-
virtual void fun(){}=0;
-
};
-
class B:public A
-
{
-
void fun()
-
{
-
cout<<"in b"<<endl;
-
}
-
};
-
-
int main()
-
{
-
A * a1 = new B();
-
a1->fun();//will print in b
-
}
-
So if you want the virtual to work then you should derive from the base class where the method is virtua.
Hope my example helps you
Raghuram
Hi,
The virtual concept works like this. -
class A
-
{
-
public:
-
virtual void fun(){}=0;
-
};
-
class B:public A
-
{
-
void fun()
-
{
-
cout<<"in b"<<endl;
-
}
-
};
-
-
int main()
-
{
-
A * a1 = new B();
-
a1->fun();//will print in b
-
}
-
So if you want the virtual to work then you should derive from the base class where the method is virtua.
Hope my example helps you
Raghuram
Hi,
Thanks for your quick reply. I understand very well your example and it refresh my memory about virtual and polymorphism. In my example which I got from a book, in creating an object I need to pass a reference of type abstract which in turn will call the callback function. I got this class to this site.
http://wiki.forum.nokia.com/index.php/How_to_read_images_to_Symbian_bitmap
Hi,
Thanks for your quick reply. I understand very well your example and it refresh my memory about virtual and polymorphism. In my example which I got from a book, in creating an object I need to pass a reference of type abstract which in turn will call the callback function. I got this class to this site.
http://wiki.forum.nokia.com/index.php/How_to_read_images_to_Symbian_bitmap
Hi,
I think you can use that way...
If my understanding is right then see my example below, which hellp you. -
#include <iostream>
-
-
using namespace std;
-
-
class A
-
{
-
public:
-
virtual void fun()=0;
-
};
-
class B:public A
-
{
-
void fun()
-
{
-
cout<<"in b"<<endl;
-
}
-
};
-
-
class Wrap
-
{
-
public:
-
void fun_wrap(A &_ipobj)
-
{
-
_ipobj.fun();
-
}
-
};
-
-
int main()
-
{
-
A * a1 = new B();
-
//a1->fun();//will print in b
-
Wrap *w1 = new Wrap();
-
w1->fun_wrap(*a1);
-
}
-
-
If i hvent got your requirements properly post again
Raghuram
Hi,
I think you can use that way...
If my understanding is right then see my example below, which hellp you. -
#include <iostream>
-
-
using namespace std;
-
-
class A
-
{
-
public:
-
virtual void fun()=0;
-
};
-
class B:public A
-
{
-
void fun()
-
{
-
cout<<"in b"<<endl;
-
}
-
};
-
-
class Wrap
-
{
-
public:
-
void fun_wrap(A &_ipobj)
-
{
-
_ipobj.fun();
-
}
-
};
-
-
int main()
-
{
-
A * a1 = new B();
-
//a1->fun();//will print in b
-
Wrap *w1 = new Wrap();
-
w1->fun_wrap(*a1);
-
}
-
-
If i hvent got your requirements properly post again
Raghuram
Hi..
Thanks...I can understand your point. Does it mean that the example class in the links above is not sufficient since I still need to add another class? If no other way, then I think I need to follow your logic.
Hi..
Thanks...I can understand your point. Does it mean that the example class in the links above is not sufficient since I still need to add another class? If no other way, then I think I need to follow your logic.
Maybe you post the code whatever u have tried and let me take a look into it.
Raghuram
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ash |
last post by:
Hello all,
I am hoping this is the appropriate newsgroup for a C++ interface
design question. I am trying to design an interface for a subscriber
to register/deregister handlers for various...
|
by: ma740988 |
last post by:
I was perusing modern C++ designs and the loki library and I might add
I hit overload when I hit select part of that book and the library.
The template _stuff_ is very intense ...... whew!!
Oso...
|
by: pakis |
last post by:
I am having a problem of pure virtual function call in my project.
Can anyone explaine me the causes of pure virtual function calls other than
calling a virtual function in base class?
Thanks
|
by: sudhir |
last post by:
I defined a pure virtual function like
virtual void sum()=0; <--- pure virtual function
but If I defined a virtual function in a base class in case of
multilevel inheritance for the base...
|
by: Marcus Kwok |
last post by:
I have processing code (I'll call it the "model") written in native
unmanaged pure C++, and I have put a GUI on top of it written using
Windows Forms (.NET 1.1). The GUI is used to set the...
|
by: sks |
last post by:
Hi ,
could anyone explain me why definition to a pure virtual function
is allowed ?
|
by: SQACPP |
last post by:
Hi,
I try to figure out how to use Callback procedure in a C++ form
project
The following code *work* perfectly on a console project
#include "Windows.h"
BOOL CALLBACK...
|
by: Nashirak |
last post by:
I am trying to implement callbacks in C++. I am modeling my callbacks
after some of the stuff that was done in wxWidgets (if anyone is
familiar with that). The syntax is as follows:
// Header...
|
by: Jack |
last post by:
Hi,
I meet a question with it ,
I did not get clear the different betteen them,
for example:
#include <iostream>
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |