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

Home Posts Topics Members FAQ

forward declarations of a data structure

I am rewriting some memory management code and I need to have a forward
declaration of a data structure. I am not converting this data structure into a
class (yet). How do I generate a forward reference of a data structure ? For
a class, I just say:

class SomeClass;

"struct SomeStructure;" does not work to forward declare the data structure.

This is the structure that I am trying to generate a vector of pointers to:

typedef struct
{ /* Used from v5.0 */
DWORD ID; /* unique ID of stream, remains unchanged in drawing */
DWORD VertxCount; /* Number of vertices on stream */
DWORD VertxIndex; /* Index of first vertex of stream */
DWORD Layer; /* Layer that stream is drawn on */
DWORD Style; /* Line-style - dotted, dashed etc */
BYTE Hatch; /* Line-hatching - cross, sine etc */
BYTE Status; /* Status of stream */
DWORD Type; /* Line-type, ALWAYS 0 at present */
} STREAM_E;
typedef STREAM_E STREAM;

Thanks,
Lynn McGuire
Jul 22 '05 #1
7 2876
Lynn wrote:
I am rewriting some memory management code and I need to have a forward
declaration of a data structure. I am not converting this data structure into a
class (yet). How do I generate a forward reference of a data structure ? For
a class, I just say:

class SomeClass;

"struct SomeStructure;" does not work to forward declare the data structure.
Huh? What do you mean by "does not work"?

This is the structure that I am trying to generate a vector of pointers to:

typedef struct
{ /* Used from v5.0 */
DWORD ID; /* unique ID of stream, remains unchanged in drawing */
DWORD VertxCount; /* Number of vertices on stream */
DWORD VertxIndex; /* Index of first vertex of stream */
DWORD Layer; /* Layer that stream is drawn on */
DWORD Style; /* Line-style - dotted, dashed etc */
BYTE Hatch; /* Line-hatching - cross, sine etc */
BYTE Status; /* Status of stream */
DWORD Type; /* Line-type, ALWAYS 0 at present */
} STREAM_E;
typedef STREAM_E STREAM;


So, you have a typedef to a typedef? I really don't understand the need
for that. Can't you simply say

struct STREAM {
DWORD ID; ...

???

V
Jul 22 '05 #2
> class (yet). How do I generate a forward reference of a data structure ? For

BTW, I am trying to generate forward references to this typedef'd data
structure in:

std::vector <STREAM *> hClipStrmList; /* List of streams on the clipbrd */

This forward refererence works OK, it is the formal declaration of the STREAM_E
data structure which is blowing up.

Thanks,
Lynn
Jul 22 '05 #3
> So, you have a typedef to a typedef? I really don't understand the need
for that. Can't you simply say

struct STREAM {
DWORD ID; ...


I am on the fifth version of this data structure. There is typedef's to
STREAM_A to STREAM_E. The latest STREAM_E structure is
typedef'd to the name STREAM. So, all throughout my code, all
I have is references to STREAM or STREAM *.

Thanks,
Lynn
Jul 22 '05 #4

"Lynn" <NO****@NOSPAM. com> wrote in message
news:co******** @library2.airne ws.net...
class (yet). How do I generate a forward reference of a data structure ?
For


BTW, I am trying to generate forward references to this typedef'd data
structure in:

std::vector <STREAM *> hClipStrmList; /* List of streams on the clipbrd */

This forward refererence works OK, it is the formal declaration of the
STREAM_E
data structure which is blowing up.

Thanks,
Lynn


Don't use that old C-style typedef stuff. Just declare the struct like
this:

struct STREAM
{ /* Used from v5.0 */
DWORD ID; /* unique ID of stream, remains unchanged in drawing */
DWORD VertxCount; /* Number of vertices on stream */
DWORD VertxIndex; /* Index of first vertex of stream */
DWORD Layer; /* Layer that stream is drawn on */
DWORD Style; /* Line-style - dotted, dashed etc */
BYTE Hatch; /* Line-hatching - cross, sine etc */
BYTE Status; /* Status of stream */
DWORD Type; /* Line-type, ALWAYS 0 at present */
};

By the way, there is no difference between a struct and a class, except the
fact that the default visibility of the members of a class is private, while
for a struct it is public. (I think the same applies for the default type
of inheritence, but I forget now.) So if you can forward-declare a class,
you can forward-declare a struct, too. I seem to recall that there was a
version of C++ long ago where a struct was used when we just wanted to have
data in the object, and a class was used when we wanted to introduce
functions to it. That's simply not the way class and struct are defined, at
least not now. It's still common practice though, to use struct for simple
data-holding objects (which have no member functions), but that's really
just because the default visibility is public. One could just as easily use
a class, and put the public: specifier before the member variables. One
other thing: just because you don't declare any member functions, doesn't
mean they don't exist. The compiler will generate certain required
functions for you, such as a constructor, destructor, copy constructor and
assignment operator, when it needs them. It's just that there's no
"user-defined" version of them. My point is: stop thinking of struct as
simply data.. it's just like a class object, except for the
public/privatedifferen ce(s).

-Howard

Jul 22 '05 #5
> Don't use that old C-style typedef stuff. Just declare the struct like this:

struct STREAM
{ /* Used from v5.0 */
DWORD ID; /* unique ID of stream, remains unchanged in drawing */
DWORD VertxCount; /* Number of vertices on stream */
DWORD VertxIndex; /* Index of first vertex of stream */
DWORD Layer; /* Layer that stream is drawn on */
DWORD Style; /* Line-style - dotted, dashed etc */
BYTE Hatch; /* Line-hatching - cross, sine etc */
BYTE Status; /* Status of stream */
DWORD Type; /* Line-type, ALWAYS 0 at present */
};


OK, I wrote my forward reference as:

struct STREAM_E;
typedef STREAM_E STREAM;

And, I changed my structure declaration to be:

struct STREAM_E
{ /* Used from v5.0 */
DWORD ID; /* unique ID of stream, remains unchanged in drawing */
DWORD VertxCount; /* Number of vertices on stream */
DWORD VertxIndex; /* Index of first vertex of stream */
DWORD Layer; /* Layer that stream is drawn on */
DWORD Style; /* Line-style - dotted, dashed etc */
BYTE Hatch; /* Line-hatching - cross, sine etc */
BYTE Status; /* Status of stream */
DWORD Type; /* Line-type, ALWAYS 0 at present */
};
typedef STREAM_E STREAM;

Seems to compile OK at the moment using VC++ 2003.

I do not like having to forward declare STREAM to be typedef'd to the
STREAM_E struct but this seems to be an evil necessity.

I need the STREAM_E because some day I expect to have STREAM_F,
STREAM_G, etc ... and there are binary versions of this data structure
(and it's previous representations ) in customer's files for the last 15 years.

This code was originally C code written in the middle 1980s and was
"loosely" converted to C++ about 1995. Life is a legacy !

Thanks,
Lynn McGuire
Jul 22 '05 #6
Lynn wrote:
Don't use that old C-style typedef stuff. Just declare the struct like this:

struct STREAM
{ /* Used from v5.0 */
DWORD ID; /* unique ID of stream, remains unchanged in drawing */
DWORD VertxCount; /* Number of vertices on stream */
DWORD VertxIndex; /* Index of first vertex of stream */
DWORD Layer; /* Layer that stream is drawn on */
DWORD Style; /* Line-style - dotted, dashed etc */
BYTE Hatch; /* Line-hatching - cross, sine etc */
BYTE Status; /* Status of stream */
DWORD Type; /* Line-type, ALWAYS 0 at present */
};

OK, I wrote my forward reference as:

struct STREAM_E;
typedef STREAM_E STREAM;

And, I changed my structure declaration to be:

struct STREAM_E
{ /* Used from v5.0 */
DWORD ID; /* unique ID of stream, remains unchanged in drawing */
DWORD VertxCount; /* Number of vertices on stream */
DWORD VertxIndex; /* Index of first vertex of stream */
DWORD Layer; /* Layer that stream is drawn on */
DWORD Style; /* Line-style - dotted, dashed etc */
BYTE Hatch; /* Line-hatching - cross, sine etc */
BYTE Status; /* Status of stream */
DWORD Type; /* Line-type, ALWAYS 0 at present */
};
typedef STREAM_E STREAM;

Seems to compile OK at the moment using VC++ 2003.

I do not like having to forward declare STREAM to be typedef'd to the
STREAM_E struct but this seems to be an evil necessity.

I need the STREAM_E because some day I expect to have STREAM_F,
STREAM_G, etc ... and there are binary versions of this data structure
(and it's previous representations ) in customer's files for the last 15 years.

This code was originally C code written in the middle 1980s and was
"loosely" converted to C++ about 1995. Life is a legacy !


I would actually use macros instead of typedefs.

V
Jul 22 '05 #7
The following link describes the use of forward declarations:

http://www.eventhelix.com/RealtimeMa...dePatterns.htm

Deepa
--
http://www.EventHelix.com/EventStudio
EventStudio 2.5 - Generate Sequence Diagrams in PDF and MS-Word

Jul 22 '05 #8

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

Similar topics

3
5469
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
6
5221
by: Steven T. Hatton | last post by:
Should I be able to forward declare something from a namespace different from the current one? For example the following code compiles: //testdriver.hpp #ifndef TESTDRIVER_HPP #define TESTDRIVER_HPP #include <ostream> namespace ns_testdriver{ using std::ostream;
11
2456
by: aleko | last post by:
This applies equally to function prototypes. Why do we have to tell the compiler twice? Other modern compiled languages don't have this requirement. Just curious, Aleko
2
508
by: Carlos Martinez Garcia | last post by:
Hi all: I usually make forward declarations in headers. Something like this: class MyClass; Now, I need a reference to a type defined like this (traditional C Style): typedef struct {
3
9283
by: Till Crueger | last post by:
Hi, I am trying to implement a tree in C and I have the folowing code: struct inner { struct node *left; struct node *right; }; struct leaf {
6
8624
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in myfile.h template<typename T,typename R> class some_class;
5
1993
by: fmassei | last post by:
Hello, I'm have a question about forward structure declarations and incomplete types. The complete structure of my file is pretty complex, but just as an example the code below will explain the problem: struct b; struct a { struct b m; }; struct b {
11
8343
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct device_t { const device_backend_t *backend; ... } device_t; typedef struct device_backend_t {
0
1479
by: Rune Allnor | last post by:
Hi all. I have these classes, implemented as templates in header files. Right now I have one file per class, where both the declarations and implementations of one class are located in each file. I would like to apply the visitor pattern to some of these classes. One of the technicalities behind the visitor pattern is that one needs forward declarations of classes, since there are two class hierarchies which refer to each other.
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...
0
10564
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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
9396
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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
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.