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

Typedef & confused ADT

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

Apr 8 '07 #1
3 1284
On 7 Apr 2007 17:13:36 -0700, fy******@gmail.com wrote:
>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?
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;
};
};
}

--
Doug Harrison
Visual C++ MVP
Apr 8 '07 #2
On Apr 7, 10:31 pm, "Doug Harrison [MVP]" <d...@mvps.orgwrote:
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:

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;
};
};

}

--
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
Apr 8 '07 #3
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


Apr 9 '07 #4

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

Similar topics

16
by: Steven T. Hatton | last post by:
In the following code, the only way I can figure out to pass an array of const is by setting the template argument to const in the instanciation expression. It would be (or seem to me) better if I...
6
by: Lorn | last post by:
I was hoping some of you might be able to help me understand the following code defining a typedef for a time query to the WINAPI. I understand the basics of what's going on, I just don't...
3
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the...
5
by: Russell Shaw | last post by:
Hi, In setjmp.h on a linux system, there is: typedef struct __jmp_buf_tag { ... } jmp_buf; I could understand typedef struct { } jmp_buf, but how do i interpret typedef struct { } jmp_buf ?
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
17
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
4
by: vcinquini | last post by:
I've always learned about typedef as a statement that creates an alias for a type. For example: typedef long DWORD; but I'm confused about the following typedef. Which is the type and which...
13
by: Ragnar | last post by:
Hi, 2 issues left with my tidy-work: 1) Tidy transforms a "&amp;" in the source-xml into a "&" in the tidied version. My XML-Importer cannot handle it 2) in a long <title>-string a wrap is...
5
by: br | last post by:
Hello World!!! I have the following code First File (.hpp) //---------------- namespace A { typedef unsigned short ushort
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.