•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,596 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,441 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1461 | Replies: 2
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I am doing cross compiling between C++ and C compiler for header files and desperately need help on figuring out namespace issue error generated by C++ compiler.
Here are two header files:abc1.h, abc2.h and a C/C++ file containing the main().
When I compile this code on C, it works fine. However whenever I compile this on C++ compiler. It gives me the following error:
g++ -g -Wall cpptest.c -o cpptest
"abc2.h:3: error: using typedef-name ‘abc’ after ‘struct’
abc1.h:9: error: ‘abc’ has a previous declaration here"
I need to have both data structure available (struct _abc and struct abc)
someone typedef the _abc to abc inside abc1.h and I cannot change this file. I can only change abc2.h and the C/C++ file.
Anyone can explain to me why C++ compiler cannot accept this?
Anyone know of solution without changing abc1.h? (a work around)
Here are two header files:abc1.h, abc2.h and a C/C++ file containing the main().
When I compile this code on C, it works fine. However whenever I compile this on C++ compiler. It gives me the following error:
g++ -g -Wall cpptest.c -o cpptest
"abc2.h:3: error: using typedef-name ‘abc’ after ‘struct’
abc1.h:9: error: ‘abc’ has a previous declaration here"
I need to have both data structure available (struct _abc and struct abc)
someone typedef the _abc to abc inside abc1.h and I cannot change this file. I can only change abc2.h and the C/C++ file.
Anyone can explain to me why C++ compiler cannot accept this?
Anyone know of solution without changing abc1.h? (a work around)
/*********** Header file abc1.h************/
#ifndef __ABC1__
struct _abc
{
int a;
int b;
}/*abc*/;
/* if I comment out The line below and uncommented the abc above, it works well.
typedef seems to be an issue in C++ compiler. However I can not touch this header file. */
typedef struct _abc abc;
#endif/*********** Header file abc2.h************/
#ifndef __ABC2__
struct abc
{
char *c;
void *d;
};
#endif/* C/C++ file named abc.c or abc.cpp */
#include "abc1.h"
#include "abc2.h"
#include <stdio.h>
int main()
{
printf("testing \n");
return 0;
} Last edited by toonces : Sep 7th, 2007 at 10:55 am.
•
•
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,307
Reputation:
Rep Power: 7
Solved Threads: 41
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I want to know if there is a work around and the reason why C++ compiler generates error while C compiler is fine with this.
I removed the comment from the abc1.h header file since it is not right.
/*********** Header file abc1.h************/
#ifndef __ABC1__
struct _abc
{
int a;
int b;
};
typedef struct _abc abc;
#endif
I removed the comment from the abc1.h header file since it is not right.
/*********** Header file abc1.h************/
#ifndef __ABC1__
struct _abc
{
int a;
int b;
};
typedef struct _abc abc;
#endif
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Visual studio (C++)
- Working with header files ??? (C)
- Header files (C++)
- doubt about header file implementation (C++)
- Does C++ indubitably have a standard? (C++)
- compile header file (C++)
- c vs h header files... (C)
- VMware help (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: MFC/ON_MESSAGE problem!!!
- Next Thread: Little bit of Homework Help would be greatly appreciated



Linear Mode