|
This
Quote: procpointer->extsymcollector.insert({ exsympointer->SYMESDID, *exsympointer }); should be instead
procpointer->extsymcollector.insert({ exsympointer->SYMESDID(), *exsympointer });
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
That gives a error of type mismatch me thinks I need a == operator inside struct esdid to tell it how to do the insert
I THINK ( because ) you are the expert anytime you try to insert a type struct the insert method needs to know how to compare therefore I think compare operators I.E == , < , >
|
|
|
|
|
That (probably) gives type mismatch because you declared the map this way
map<ESDID, syminfo>
But you shouldn't do that. Instead you should declare it like
map <uint32_t, syminfo>
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
now I am I am getting
this
]
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '1': no conversion from 'ESDID' to 'std::pair<const uint32_t,syminfo>'
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '2': no conversion from 'syminfo' to 'std::pair<const uint32_t,syminfo>'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xtree(1283,10): message : see declaration of 'std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::insert'
1> with
1> [
1> _Kty=uint32_t,
1> _Ty=syminfo,
1> _Pr=std::less<uint32_t>,
1> _Alloc=std::allocator<std::pair<const uint32_t,syminfo>>
1> ]
|
|
|
|
|
Did you try
procpointer->extsymcollector.insert(std::pair<uint32_t, syminfo>(exsympointer->SYMESDID(), *exsympointer )); ?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
still getting type mismatch will have to look at this after work think it maybe using compare operators in the struct thank you
|
|
|
|
|
The complier was screaming for < operator so I give it what wants hope this works got a clean complie
const struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
BOOL operator< (const ESDID x) const { return c < x.c; }
};
|
|
|
|
|
That compiles. However it is probably NOT what you want (both the key of the map and the < operator use the address of the c array).
Run
ESDID e1, e2;
e1.c[0] = e1.c[1] = e1.c[2] = e1.c[3] = 'A';
e2.c[0] = e2.c[1] = e2.c[2] = e2.c[3] = 'A';
cout << std::boolalpha;
cout << "(e1 < e2) " << (e1 < e2) << "\n";
cout << "(e2 < e1) " << (e2 < e1) << "\n";
and watch the resulting output. Can you spot the problem?
You can do something like this:
struct ESDID
{
char c[4];
operator uint32_t () const { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
syminfo s1;
map <uint32_t, syminfo> m;
m.insert( pair<uint32_t, syminfo>(s1.symesdid, s1) );
Note the key of the map uses the content of the c array.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I understand the compare wont work correctly however what I dont see where the cast operator () is being used> Is dynamic cast used with pair i.e <> the same as the () operator ()
|
|
|
|
|
The cast is used here:
pair<uint32_t, syminfo>(s1.symesdid, s1)
The compiler: "Map's key must be a uint32_t , hence s1.symesdid , being an ESDID , does NOT fit.
Let's see if there is a suitable cast..."
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Alternatively you could use a union?
const struct ESDID
{
union
{
char c[4];
uint32_t i;
} x;
bool operator< (const ESDID e) const { return x.i < e.x.i; }
};
|
|
|
|
|
thanks richard I dont see in the map documentation when using the insert method with key of type struct '<' operator must be overloaded by the user
|
|
|
|
|
Actually there is (see std::map - cppreference.com[^]):
template<
class Key,
class T,
class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>
> class map; As it should be, because the std::map is a sorted container.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
|
cppreference.com:
template<
class Key,
class T,
class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>
> class map;
Microsoft:
template <class Key,
class Type,
class Traits = less<Key>,
class Allocator=allocator<pair <const Key, Type>>>
class map;
Do you see significant differences?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I see the third parameter to the template in microsoft docs is class traits in the cpp reference its class compare thank you
|
|
|
|
|
That's, you know, just a matter of naming...
BTW, you are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code
Thank
|
|
|
|
|
It is just as easy to catch the exception. Exceptions are another useful feature of OOP languages, and provide more flexibility than simple return codes.
|
|
|
|
|
|
Thank you again you know I’m an assembler mail framer by birth when I post any question on IBMMAIN no matter how much research I have done I get screamed at wish IBMMAIN could be more like the codeproject thank.
Time for to implement my code or actually yours
|
|
|
|
|
<pre>in my applications need some scanner support ,I thought it is a good idea to get into TWAIN and try it out.after that I had an exit error that is driving me nuts as an Debug Assertion Failed....
in cmdtarg.cpp line 40 CCmdTarget::~CCmdTarget because m_dwRef is greater than 1 (in this case it is 2)
|
|
|
|
|
|
I working in an embedded environment (STM32 microcontroller) and I compile using GCC (STM32CubeIDE). I want to put a C++ object inside a struct and this is the only way I could get it to compile:
namespace MyNamespace {
class MyObject
{
int m_i;
public:
MyObject(int i):m_i(i){}
MyObject(const MyObject&) = delete;
};
}
typedef struct {
MyNamespace::MyObject* MyObject;
} MyStruct_s;
static MyStruct_s MyStruct = {new MyNamespace::MyObject(0) }; However, I'm having strange hanging issues in my code and I suspect the code above might be the cause. Is the code above legal or will it corrupt RAM? If so, what's the correct way to do it? Ideally I'd like to have the whole object inside the struct, not just a pointer to it.
modified 5-Dec-22 8:23am.
|
|
|
|
|
As matter of fact, you don't need a pointer. Try
#include <iostream>
using namespace std;
namespace MyNamespace
{
class MyObject
{
int m_i;
public:
MyObject(int i):m_i(i){}
int get_i(){return m_i;}
};
}
struct MyStruct
{
MyNamespace::MyObject myObject;
};
static MyStruct s_myStruct = { MyNamespace::MyObject(5) };
int main()
{
cout << s_myStruct.myObject.get_i() << endl;
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|