N
Ninan
Is this a good design for myClass in the example below? Are there
better alternatives for m_oA and myCallback?
struct apiA, and function apiFn () are not in my control, as they are
standard api supplied by the exchange for which I am writing the
application. Also the member variable m_oA logically belongs to myClass
struct apiA {
int a;
int b;
} ;
typedef void (apiCallback) (apiA* pA);
void apiFn (apiA *pA, apiCallback *pCbk)
{
std::cout << pA->a << " " << pA->b << std::endl;
pA->a = 8;
pA->b = 9;
std::cout << pA->a << " " << pA->b << std::endl;
//Simple illustration only. In real life callback fn will be
called later pA->a = 18;
pA->b = 19;
(*pCbk)(pA);
return;
}
class myClass {
apiA m_oA;
public:
void UseapiFn () ;
static void myCallback (apiA *pA) ;
} ;
void
myClass::UseapiFn ()
{
m_oA.a =6;
m_oA.b =7;
apiFn (&m_oA, myCallback);
}
void myClass::myCallback (apiA *pA)
{
std::cout << "In callback " << pA->a << " " << pA->b <<
std::endl;
return;
}
int main ()
{
myClass oInst;
oInst.UseapiFn();
return 0;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
better alternatives for m_oA and myCallback?
struct apiA, and function apiFn () are not in my control, as they are
standard api supplied by the exchange for which I am writing the
application. Also the member variable m_oA logically belongs to myClass
struct apiA {
int a;
int b;
} ;
typedef void (apiCallback) (apiA* pA);
void apiFn (apiA *pA, apiCallback *pCbk)
{
std::cout << pA->a << " " << pA->b << std::endl;
pA->a = 8;
pA->b = 9;
std::cout << pA->a << " " << pA->b << std::endl;
//Simple illustration only. In real life callback fn will be
called later pA->a = 18;
pA->b = 19;
(*pCbk)(pA);
return;
}
class myClass {
apiA m_oA;
public:
void UseapiFn () ;
static void myCallback (apiA *pA) ;
} ;
void
myClass::UseapiFn ()
{
m_oA.a =6;
m_oA.b =7;
apiFn (&m_oA, myCallback);
}
void myClass::myCallback (apiA *pA)
{
std::cout << "In callback " << pA->a << " " << pA->b <<
std::endl;
return;
}
int main ()
{
myClass oInst;
oInst.UseapiFn();
return 0;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]