Would you please show me why find doesn't work in my codes below? I always got a segfault.
**************************
Expand|Select|Wrap|Line Numbers
- port* macro::get_port(char* myName) {
- printf ("Getting port %s\n",myName);
- port* hey = new port;
- for (_ITER=_PORTS->begin();_ITER!=_PORTS->end();++_ITER) {
- printf("Port %s existed!\n",_ITER->first);
- port* tmp = _ITER->second;
- printf("Port %s has direction %s\n",tmp->get_name(),tmp->get_dir());
- }
- if ((_ITER = _PORTS->find(myName)) == _PORTS->end())
- printf("Could not find %s in map\n",myName);
- else {
- _ITER = _PORTS->find(myName);
- printf("Port %s is found\n",_ITER->first);
- }
- return (hey);
- }
The output is below
Port P2 existed!
Port P2 has direction OUTPUT
Port PA existed!
Port PA has direction OUTPUT
Port P3 existed!
Port P3 has direction INOUT
Could not find P2 in map
*********************
When I test the map in a loop it looks fine. But when I try to find a particular element, it said it couldn't find it. Would you please help me find out the error as I am new to C++ and have spent almost a week on this.
Thank you,
--Binh Pham