473,786 Members | 2,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_INTER NAL_H_
#define _XML_IMPL_INTER NAL_H_

class QString;
class QVariant;

namespace xml_impl {
void unknownType(con st QString& functionName, const QVariant::Type& type);
void ni(const QString& functionName);
}
#endif
/*************** **************
* compiler error messages
.../../include/xml_impl/xml_impl_intern al.h:7: error: expected unqualified-id
before ?&? token
.../../include/xml_impl/xml_impl_intern al.h:7: error: expected ?,? or ?...?
before ?&? token
.../../include/xml_impl/xml_impl_intern al.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 2784
* 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_INTER NAL_H_
#define _XML_IMPL_INTER NAL_H_

class QString;
class QVariant;

namespace xml_impl {
void unknownType(con st QString& functionName, const QVariant::Type& type);
void ni(const QString& functionName);
}
#endif
/*************** **************
* compiler error messages
../../include/xml_impl/xml_impl_intern al.h:7: error: expected unqualified-id
before ?&? token
../../include/xml_impl/xml_impl_intern al.h:7: error: expected ?,? or ?...?
before ?&? token
../../include/xml_impl/xml_impl_intern al.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_INTER NAL_H_
#define _XML_IMPL_INTER NAL_H_

class QString;
class QVariant;

namespace xml_impl {
void unknownType(con st QString& functionName, const QVariant::Type&
type); void ni(const QString& functionName);
}
#endif
/*************** **************
* compiler error messages
../../include/xml_impl/xml_impl_intern al.h:7: error: expected
unqualified-id before ?&? token
../../include/xml_impl/xml_impl_intern al.h:7: error: expected ?,? or
?...? before ?&? token
../../include/xml_impl/xml_impl_intern al.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
5467
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
37096
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 explicitly say about enum's forward declaration, but one example shows it in 18.2.1, clause 4:
10
2233
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 if anyone can tell me why my forward class declarations not working. the member function findpaths can't seem to access the class Board when I try to pass it a board object by value. I put the Board class latrerbut also put in a forward...
2
2820
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? Or more generally, can I forward declare a typedef or an enum? Also, is
5
1882
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 (some_namespace::Foo), -------------------------------- snip -------------------------------- #ifndef GUARD_Foo_HPP #define GUARD_Foo_HPP namespace some_namespace {
7
2873
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 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:
2
2297
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 getting a lot of problems, but it may not be due to
9
2012
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
5375
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 Colour
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.