473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Redeclaration error when forward declaraing a structure

Hi all,

I hav a file which is actually linkage file (used as an reference
interface between c and c++ files). And this file has got two
structures in it .. When i include this file directly i dont have any
issues. but according to some norms in the review I am not supposed to
use this file direclty in the header file .. but its fine if i use that
inside the corresponding file.

To avoid compiler error, i forward declared the structure as in ex.

struct MyStruct;

class MyClass
{
private :
MyStruct * me;
}

But when the actual cpp file which includes the prev file i mentioned
in the beginning I get a compiler error in actual file which has the
structure defintion.

say like : structure redefined, see myclass.cpp (some thing like this)

So i tried replacing this structure in the linkage .h file to a class
and forward declared it on the MyClass.cpp file.

ex:
//typedef struct
//{
// char *myName;
}MyStruct;

to

class MyStruct
{
public:
char *myName;
}

Now the build is perfect once i forward declare the class..

Do find any reason for it .. Do you find any error in my forward
declaration of struct..
Can u please help me .. what could be the solution.?

Nov 16 '06 #1
3 4080
* Dh*********@gmail.com:
>
Now the build is perfect once i forward declare the class..
Good for you.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 16 '06 #2
I didnt get u .. :( ??

Alf P. Steinbach wrote:
* Dh*********@gmail.com:

Now the build is perfect once i forward declare the class..

Good for you.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 16 '06 #3

<Dh*********@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
Hi all,

I hav a file which is actually linkage file (used as an reference
interface between c and c++ files). And this file has got two
structures in it .. When i include this file directly i dont have any
issues. but according to some norms in the review I am not supposed to
use this file direclty in the header file .. but its fine if i use that
inside the corresponding file.

To avoid compiler error, i forward declared the structure as in ex.

struct MyStruct;

class MyClass
{
private :
MyStruct * me;
}

But when the actual cpp file which includes the prev file i mentioned
in the beginning I get a compiler error in actual file which has the
structure defintion.

say like : structure redefined, see myclass.cpp (some thing like this)
Redefinition errors are often caused by not using "include guards" in
headers which are included by multiple source files. (But given the rest of
your post, I doubt that's the problem here.)

It's difficult to tell what's wrong when you use such vague language (like
"the actual file"). Be specific, and include the actual code, where
possible.
So i tried replacing this structure in the linkage .h file to a class
and forward declared it on the MyClass.cpp file.

ex:
//typedef struct
//{
// char *myName;
}MyStruct;
That's an old-style C declaration. To define a struct in C++, do it like
this:

struct MyStruct
{
char* myName;
};

There's no need to change it to a class type if you don't need it to be. A
struct type will work also. Just use the modern definition style above, not
that old typedef stuff.
to

class MyStruct
{
public:
char *myName;
}

Now the build is perfect once i forward declare the class..
It shouldn't. It's missing the semicolon (;) at the end of the class
definition.
>
Do find any reason for it .. Do you find any error in my forward
declaration of struct..
Can u please help me .. what could be the solution.?
I'm guessing, but possibly because of the use of a typedef?

-Howard

Nov 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ajay Brar | last post by:
hi! i get a value error when parsing an xml file. This is because it can't find the DTD - ValueError: unknown url type: ../um_xml/um.dtd From what i have discovered in the archives, this...
4
by: D Witherspoon | last post by:
I have a Structure I have created and am using it as a Public Property of a class. Here is the property. ------------------------------------------------------ Dim _MyID As SInteger Public...
1
by: sreak | last post by:
Need to find the cause of the following error: The sample code goes as follows:( file name version.cpp ) #include <iostream> struct version { int val; }; int main()
6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
1
by: Matt | last post by:
When I try to run the ASP.NET application, it has the following error messages: Error while trying to run project: unable to start debugging on the web server. The project is not configured to...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
2
by: Chris | last post by:
I am getting a viewstate error when adding dynamically user controls. SYSTEM_EXCEPTION:Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree...
5
by: mackenzie | last post by:
Hello, I am looking for a little bit of help. I am trying to create a dynamically allocated object which contains one or more objects of type boost::pool<>. I get a compiler error when an object...
13
by: smiler2505 | last post by:
Sub cmbEnt_NotInList(NewData As String, Response As Integer) Answer = MsgBox("add?", vbYesNo, "add?") If Answer = vbYes Then DoCmd.Close acForm, "frmOrd" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.