Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Forward declarations of class member enums?

Reply
Thread Tools

Forward declarations of class member enums?

 
 
Steven T. Hatton
Guest
Posts: n/a
 
      11-18-2006
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/
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-18-2006
* 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?
 
Reply With Quote
 
 
 
 
Steven T. Hatton
Guest
Posts: n/a
 
      11-20-2006
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forward class declarations Belebele C++ 4 09-01-2008 03:51 PM
Usage of class forward declarations; Belebele C++ 2 08-29-2008 06:06 PM
gcc, class forward declarations and destructor calls Juha Nieminen C++ 3 03-05-2007 04:46 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
member variable declaration and forward declarations John Ratliff C++ 2 08-26-2005 07:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57