473,323 Members | 1,622 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,323 software developers and data experts.

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 2836
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.airnews.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/privatedifference(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
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
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...
11
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
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
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
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...
5
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...
11
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...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.