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

Forward declarations of class member enums?

This is not a big deal. It just bothers me that I don't see a way around
including the header for QVariant in the following:

#ifndef _XML_IMPL_INTERNAL_H_
#define _XML_IMPL_INTERNAL_H_

class QString;
class QVariant;

namespace xml_impl {
void unknownType(const QString& functionName, const QVariant::Type& type);
void ni(const QString& functionName);
}
#endif
/*****************************
* compiler error messages
.../../include/xml_impl/xml_impl_internal.h:7: error: expected unqualified-id
before ?&? token
.../../include/xml_impl/xml_impl_internal.h:7: error: expected ?,? or ?...?
before ?&? token
.../../include/xml_impl/xml_impl_internal.h:7: error: ISO C++ forbids
declaration of ?parameter? with no type
*****************************/

Is there any way to get around providing the definition of QVariant::Type
prior to the function declaration?

--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Nov 18 '06 #1
2 2758
* Steven T. Hatton:
This is not a big deal. It just bothers me that I don't see a way around
including the header for QVariant in the following:

#ifndef _XML_IMPL_INTERNAL_H_
#define _XML_IMPL_INTERNAL_H_

class QString;
class QVariant;

namespace xml_impl {
void unknownType(const QString& functionName, const QVariant::Type& type);
void ni(const QString& functionName);
}
#endif
/*****************************
* compiler error messages
../../include/xml_impl/xml_impl_internal.h:7: error: expected unqualified-id
before ?&? token
../../include/xml_impl/xml_impl_internal.h:7: error: expected ?,? or ?...?
before ?&? token
../../include/xml_impl/xml_impl_internal.h:7: error: ISO C++ forbids
declaration of ?parameter? with no type
*****************************/

Is there any way to get around providing the definition of QVariant::Type
prior to the function declaration?
Assuming it's your own thing, just do

class QVariantType;

and in your function (which smells of non-OO)

void unknownType(
QString const& functionName, QVariantType const& type
);

and wherever you're definining class QVariant

class QVariantType { ... };
class QVariant
{
public:
typedef QVariantType Type;
};
--
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 18 '06 #2
Alf P. Steinbach wrote:
* Steven T. Hatton:
>This is not a big deal. It just bothers me that I don't see a way around
including the header for QVariant in the following:

#ifndef _XML_IMPL_INTERNAL_H_
#define _XML_IMPL_INTERNAL_H_

class QString;
class QVariant;

namespace xml_impl {
void unknownType(const QString& functionName, const QVariant::Type&
type); void ni(const QString& functionName);
}
#endif
/*****************************
* compiler error messages
../../include/xml_impl/xml_impl_internal.h:7: error: expected
unqualified-id before ?&? token
../../include/xml_impl/xml_impl_internal.h:7: error: expected ?,? or
?...? before ?&? token
../../include/xml_impl/xml_impl_internal.h:7: error: ISO C++ forbids
declaration of ?parameter? with no type
*****************************/

Is there any way to get around providing the definition of QVariant::Type
prior to the function declaration?
Assuming it's your own thing, just do
Sorry, after I sent the message I realized I had not been very clear about
the situation. QVariant is a class in Qt. It's kind of like an OO
extension of a union that uses a type property to communicate it's content
type. The variable of type QVariant::Type I was trying to pass is
actualized by one of the enumerators.

Here's the doc on QVariant if you happen to be interested:
http://doc.trolltech.com/4.2/qvariant.html
class QVariantType;

and in your function (which smells of non-OO)
You are quite perceptive. I have a stateless translator function which has
no legitimate reason to be in a class. I put it and it's cousins in a
small namespace, and exposed it through an interface namespace.

http://bridgewater.wordpress.com/200...nguage-item-1/
void unknownType(
QString const& functionName, QVariantType const& type
);

and wherever you're definining class QVariant

class QVariantType { ... };
class QVariant
{
public:
typedef QVariantType Type;
};
Something crossed my mind today, but I'm not sure I should really admit I
entertained the notion. Following Peano one might construct enumerated
types as

struct Integer{};
struct Zero: public Integer{};
struct One: public Zero{};
struct Two: public One{};
....
struct NPlusOne: public N{};

That, in itself weighs nothing at runtime because there are no virtual
functions. OTOH, the ordering is lost at runtime. It has the advantage
over enumerations that you cannot use a value you have not explicitly
specified. One could do something similar to what Robe did with r++
http://websvn.kde.org/branches/work/...25&view=markup

And for grins you could even throw in a static const char* so you could dump
the name if you needed it for something like an XML builder.

Yet another option might be to use template metaprogramming to recursively
enumerate the items. Yet another would be to do some kind of
initialization at load time assigning the value of an incremented counter
to each instance sequentially. Why don't I like enums? Mostly because the
aren't really enumerations.
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Nov 20 '06 #3

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 { /* .... */ }
11
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't...
10
by: Alan Lee | last post by:
Hi i am writing a small simulation for a bunch of atoms jumping around on a surface. I know i am a crappy programmer since i am not very familiar with object oriented languages. I am woindering...
2
by: Marcin Kalicinski | last post by:
Hi All, In some headers meant to work with both C and C++ the following is often found: typedef struct tagMyStruct { /*some members*/ } MyStruct; Can I forward-declare MyStruct somehow? ...
5
by: John Gabriele | last post by:
I'm hoping someone can please help me remember the C++ rule: When you're writing a header file for a class (say, some_namespace::Bar), and that class makes use of another class...
7
by: Lynn | last post by:
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...
2
by: John Ratliff | last post by:
I'm having issues with forward declarations and possibly member variables. Can you declare a member variable and pass it parameters. class x { private: y obj(this); } Is that valid? I'm...
9
by: vishnu | last post by:
what is the exact difference between including a class header file and forward declaration. and Is there a case , where in forward declaration is not possible and including is .
4
by: Steve | last post by:
Hi, I always though to return an instance of a class by value, it had to be defined - i.e. forward declaration isn't good enough? Consider the following code snippet: class RGBA; class...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.