Implementation dilema

M

ma740988

Puzzled about an implementation here. In a vendor file, I'm faced:

// vendors_file.h
#ifdef __cplusplus
typedef void (*VOIDFUNCPTR) (...); /* pfunction returning
void */
#else
typedef void (*VOIDFUNCPTR) (); /* pfunction
returning void */
#endif /* __cplusplus */

enum TT {
jdx,
kdx
};

bool do_a_special_thing( TT t, int prior );
// end vendors_file.h

For starters, the names reflected in the enum and the function
do_a_special_thing aren't the actual names nonetheless, for test code
I've got:

// my_file.cpp
# include <iostream>
# include <list>
# include <vector>
# include "vendors_file.h"

using namespace std;

struct MYSTRUCT {
TT m;
int prior;
};

class FOO {
static void test_funct(...) {}
static void test_funct2(...) {}

std::map< TT, VOIDFUNCPTR> myMap;
MYSTRUCT my;

public:
FOO( list<MYSTRUCT>& lst) :
my(MYSTRUCT())
{
for (size_t idx(0); idx < lst.size(); ++idx)
{
//if ( test_funct3(lst[0]) )
//{
//}
}

myMap[jdx] = test_funct;
my.m = jdx;

if ( myMap.find(my.m) == myMap.end())
{
cout << " NOT FOUND " << endl;
}
else {
cout << " FOUND " << endl;
}

map<TT, VOIDFUNCPTR>::iterator it = myMap.begin();
for (; it != myMap.end(); ++it)
{
if ((*it).first == jdx) {
cout << " OK " << endl;
}
}
}

bool test_funct3( MYSTRUCT& tStruct)
{
// call vendor function do_a_special_thing
if ( do_a_special_thing( tStruct.m, tStruct.prior))
{
}
}
};

Here's my dilema: The constructor of FOO takes a list of 'MYSTRUCT'
as a passed parameter. Trouble is, I need to call the test_funct3
member function (see commented out code in constructor) for each
'MYSTRUCT' element in the list. Trouble is, there's no way for me to
do that with a list or any container type that I could think of. How
could I achieve my objective while maintiaining test_func3?

One approach would be to iterate throught the 'list' of items and call
'do_a_special_thing' directly inside the constructor of FOO.

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top