Error "Symbol 'pair' could not be resolved" when using typedef [message #1829285] |
Tue, 30 June 2020 13:25 |
Dave Rathnow Messages: 25 Registered: March 2014 |
Junior Member |
|
|
OS: Ubuntu 18.04
Eclipse Version: 2020-03 (4.15.0)
Build id: 20200313-1211
CDT: 9.11
Project: C/C++ with self-managed makefile
I create two files: foo.h and foo.cpp:
foo.h:
#ifndef FOO_H_
#define FOO_H_
#include <stdint.h>
typedef struct
{
uint8_t dataType;
uint16_t offset;
uint32_t ioId;
} header_t;
#endif
foo.cpp:
#include "foo.h"
#include <map>
using namespace std;
int main(int argc, char **argv)
{
header_t header;
map<uint32_t, header_t> theMap;
theMap.insert(pair<uint32_t, header_t>(1, header));
}
When I open foo.cpp in CDT editor, the editor displays a red line under
theMap.insert(pair<uint32_t, header_t>(1, header))
^-----------------------^
When I mouse over the line, the editor shows the error "Symbol 'pair' could not be resolved" and yet the file compiles fine.
However, if I put everything into a single file
#include <map>
#include <stdint.h>
typedef struct
{
uint8_t dataType;
uint16_t offset;
uint32_t ioId;
} header_t;
using namespace std;
int main(int argc, char **argv)
{
header_t header;
map<uint32_t, header_t> theMap;
theMap.insert(pair<uint32_t, header_t>(1, header));
}
I get no error and everything still compiles. I've also noticed that if I change my typedef to
typedef struct _header_t
{
uint8_t dataType;
uint16_t offset;
uint32_t ioId;
} header_t
or just use 'struct', and my map declaration to
header_t header;
map<uint32_t, _header_t> theMap;
theMap.insert(pair<uint32_t, _header_t>(1, header));
I get no errors in the editor and everything still compiles.
What quirk in the editor is causing this? Is there a way to fix this so it doesn't display the red line?
|
|
|
Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829297 is a reply to message #1829285] |
Wed, 01 July 2020 06:02 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
Since you haven't told us how your project is structured or how it was constructed, we can only guess what the cause is.
By "self-managed makefile" I assume you mean a Makefile project vs. a Managed Build project.
It appears the Indexer doesn't know how to find foo.h
At least that's what happened when I had foo.h in a directory named inc
When I moved it to the src directory where the .cpp is stored, everything was resolved after the Indexer had run.
FWIW I tested this with 2020-06
There are a number of ways to inform the Indexer where header files are located.
The Indexer uses the information found in
Project --> Properties --> C/C++ General --> Preprocessor Include Paths, Macros etc.
which can be populated manually or via various providers.
I moved foo.h back into inc
then told the Indexer to look there.
This also worked.
[Updated on: Wed, 01 July 2020 06:17] Report message to a moderator
|
|
|
Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829343 is a reply to message #1829297] |
Wed, 01 July 2020 16:02 |
Dave Rathnow Messages: 25 Registered: March 2014 |
Junior Member |
|
|
David,
Thanks for the reply but this isn't an issue with the indexer not finding my include file. I can put other declarations in the include file and the indexer finds them fine.
To illustrate my point, I created a new empty "C++ Managed Build" project and dropped foo.h and foo.cpp into the project directory. I then modified them as shown below. The files compile fine but Eclipse editor is still showing me the error, as shown in the attached screenshot.
#ifndef FOO_H_
#define FOO_H_
#include <stdint.h>
typedef struct
{
uint8_t dataType;
uint16_t offset;
uint32_t ioId;
} header_t;
struct header {
uint8_t dataType;
uint16_t offset;
uint32_t ioId;
};
#endif
#include "foo.h"
#include <map>
using namespace std;
int main(int argc, char **argv)
{
struct header structHeader;
header_t typedefHeader;
map<uint32_t, struct header> structHeaderMap;
map<uint32_t, header_t> typedefHeaderMap;
structHeaderMap.insert(pair<uint32_t, struct header>(1, structHeader));
typedefHeaderMap.insert(pair<uint32_t, header_t>(1, typedefHeader));
}
|
|
|
|
|
|
|
|
|
|
Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829628 is a reply to message #1829627] |
Tue, 07 July 2020 22:33 |
Dave Rathnow Messages: 25 Registered: March 2014 |
Junior Member |
|
|
Thanks and yes, I understand all that and I've done the searching to make sure there are no other typedefs in any of the includes I've used (or the ones they use) with that name. Still, even with an explicit namespace in the declaration (i.e. pair<uint32_t, foo::header_t>), it still shows an error.
I should also add that if it were a clash of names, the project wouldn't compile and that's not the case. The project does build.
[Updated on: Tue, 07 July 2020 22:35] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05594 seconds