Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

Typedef & confused ADT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fyderniX@gmail.com - 08 Apr 2007 01:13 GMT
Heya.  I have a header file that looks similar to this:

namespace mupdf {

    public class Data
    {
    public:
        typedef struct fz_stream_s fz_stream;

        struct fz_stream_s
        {
            int refs;
            int kind;
            int mode;
            int dead;
            fz_buffer *buffer;
            fz_filter *filter;
            fz_stream *chain;
            fz_error *error;
            int file;
        };
       };
}

When I try to create"mupdf::Data::fz_stream fileStream;" it gives me
grief, however:

.\sandbox2.cpp(18) : error C2079: 'fileStream' uses undefined struct
'mupdf::fz_stream_s'

"fz_stream_s" clearly exists from within the "Data" class.  Why is the
compiler looking for it way up in the "mupdf" namespace?  What am I
doing wrong?

SigmaX
Doug Harrison [MVP] - 08 Apr 2007 03:31 GMT
>Heya.  I have a header file that looks similar to this:
>
[quoted text clipped - 29 lines]
>compiler looking for it way up in the "mupdf" namespace?  What am I
>doing wrong?

Types that are first encountered in declarations such as this interpreted
as living in the enclosing namespace. To solve the problem, forward declare
the type:

namespace mupdf {

    public class Data
    {
    public:
          struct fz_stream_s;
        typedef struct fz_stream_s fz_stream;

        struct fz_stream_s
        {
            int refs;
            int kind;
            int mode;
            int dead;
            fz_buffer *buffer;
            fz_filter *filter;
            fz_stream *chain;
            fz_error *error;
            int file;
        };
       };
}

This tells the compiler that fz_stream_s is a member of Data and not the
enclosing namespace. That said, I don't know why you don't go with the
simpler:

namespace mupdf {

    public class Data
    {
    public:

        struct fz_stream
        {
            int refs;
            int kind;
            int mode;
            int dead;
            fz_buffer *buffer;
            fz_filter *filter;
            fz_stream *chain;
            fz_error *error;
            int file;
        };
       };
}

Signature

Doug Harrison
Visual C++ MVP

fyderniX@gmail.com - 08 Apr 2007 15:07 GMT
> Types that are first encountered in declarations such as this interpreted
> as living in the enclosing namespace. To solve the problem, forward declare
> the type:

Thanx.  That should be what I needed to know.

> That said, I don't know why you don't go with the
> simpler:
[quoted text clipped - 24 lines]
> Doug Harrison
> Visual C++ MVP

Well, I'm actually writing a wrapper for a library somebody else made,
and that's how they set up most all their structs.  I'm not sure their
reasoning for the alias, but I figured I'd use it just in case it's
important ;-).

SigmaX
Ben Voigt - 09 Apr 2007 15:11 GMT
> Well, I'm actually writing a wrapper for a library somebody else made,
> and that's how they set up most all their structs.  I'm not sure their
> reasoning for the alias, but I figured I'd use it just in case it's
> important ;-).

Is that library perhaps written in C, not C++?  In that case, you'd have to
specify "struct Blah" everywhere, the typedef allows you to avoid needing
the keyword "struct" everywhere.  But C++ doesn't need the extra "struct",
even without a typedef.

> SigmaX

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.