473,837 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4107
* Dh*********@gma il.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*********@gma il.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*********@gm ail.comwrote in message
news:11******** *************@f 16g2000cwb.goog legroups.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
2251
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 happens when your XML and DTD file are not in your current directory i have the directory structure home
4
1606
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 Property MyID() As SInteger Get
1
1563
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
2864
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 fine while the file was in the project directory. When the obsolete file was removed from the project directory, my application will no longer compile. Can someone please help with this issue? Thank in advance, Tom
1
1862
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 be debugged
5
3655
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 New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
2
1963
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 that was used to save viewstate during the previous request. My understanding is that the information about the controls getting posted back has to match the controls being created. When they don't match, this is what creates the error. The...
5
2852
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 of this type is contained in my class and am not sure why. To be honest I have a little but not a lot of experience with templates and it could simply be obvious to a more experienced template user; however, the answer escapes me. Here is a...
13
3216
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" CurrentDb().TableDefs("tblOrd").Fields("Ent").RowSource = CurrentDb().TableDefs("tblOrd").Fields("Ent").RowSource & ";" & NewData Else
0
9839
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10621
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10268
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7806
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5668
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5846
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3123
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.