I could use String objects with this, but this code has to interact with fortran and C code through an RDMA transport on Jaguar (Titan), so serializing and sending complex objects isn't possible (certainly possible for me to use internally, though).
Basically, I'm trying to maintain a map of transactions, identified by name. However, I can't seem to use the "find" method on my map. Here's an example of what I'm trying to do (real code is export controlled, so this is a good mimic):
The compile error is:Code:#include <map> #include <stdio.h> #define TRANSACTION_NAME_SIZE 32 struct _txn_string { char name[TRANSACTION_NAME_SIZE]; }; typedef struct _txn_string txn_string; struct _mpi_sub_tx { char name[TRANSACTION_NAME_SIZE]; int num_operations; }; typedef struct _mpi_sub_tx mpi_sub_tx; class compare_txn_string{ public: bool operator()(const txn_string * str1, const txn_string * str2) { return strncmp(str1->name, str2->name, TRANSACTION_NAME_SIZE); } }; using namespace std; int main() { map<txn_string*, mpi_sub_tx*> buckets(compare_txn_string()); txn_string * str1 = new txn_string(); mpi_sub_tx * sub1 = new mpi_sub_tx(); strcpy(str1->name, "hello"); strncpy(sub1->name, str1->name, TRANSACTION_NAME_SIZE); printf("str name: %s sub1 name: %s\n", str1->name, sub1->name); if(buckets.find(str1) == buckets.end()) buckets[str1] = sub1; return 0; }
Ideally, the if statement should be true as I haven't entered anything in the map yet...Code:g++ -o stupid stupid.cpp stupid.cpp: In function ‘int main()’: stupid.cpp:38: error: request for member ‘find’ in ‘buckets’, which is of non-class type ‘std::map<txn_string*, mpi_sub_tx*, std::less<txn_string*>, std::allocator<std::pair<txn_string* const, mpi_sub_tx*> > > ()(compare_txn_string (*)())’ stupid.cpp:38: error: request for member ‘end’ in ‘buckets’, which is of non-class type ‘std::map<txn_string*, mpi_sub_tx*, std::less<txn_string*>, std::allocator<std::pair<txn_string* const, mpi_sub_tx*> > > ()(compare_txn_string (*)())’ stupid.cpp:39: error: invalid types ‘std::map<txn_string*, mpi_sub_tx*, std::less<txn_string*>, std::allocator<std::pair<txn_string* const, mpi_sub_tx*> > > ()(compare_txn_string (*)())[txn_string*]’ for array subscript
Any ideas what my misconception is?



LinkBack URL
About LinkBacks



