473,621 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"virtual outside class declaration" and "declaratio n does not declare anything"

This little bit of seeminly innocent code seems to give me these two
errors, all on the line that declares check(). Is there some part of
C++ that I'm missing out on?

class Condition {
public:
Condition() {}
virtual ~Condition() {}

virtual bool check() const;
};

class AndCondition : public Condition {
std::vector<Con dition> conditionList;

public:
AndCondition(st d::vector<Condi tion> list =
std::vector<Con dition>()) : conditionList(l ist) {}
virtual ~AndCondition() {}

std::vector<Con dition>& getConditionLis t() { return
conditionList; }
const std::vector<Con dition>& getConditionLis t() const { return
conditionList; }

bool check() const;
};

/* more classes that extend Condition here */

--
I am only a mirage.
Jul 23 '05 #1
6 9744
"kelvSYC" <ke*****@no.ema il.shaw.ca> wrote in message
news:1705200500 10511072%ke**** *@no.email.shaw .ca
This little bit of seeminly innocent code seems to give me these two
errors, all on the line that declares check(). Is there some part of
C++ that I'm missing out on?

class Condition {
public:
Condition() {}
virtual ~Condition() {}

virtual bool check() const;
};

class AndCondition : public Condition {
std::vector<Con dition> conditionList;

public:
AndCondition(st d::vector<Condi tion> list =
std::vector<Con dition>()) : conditionList(l ist) {}
virtual ~AndCondition() {}

std::vector<Con dition>& getConditionLis t() { return
conditionList; }
const std::vector<Con dition>& getConditionLis t() const { return
conditionList; }

bool check() const;
};

/* more classes that extend Condition here */

VC++ 7.1 and Comeau both accept your code without complaint. What compiler
are you using?

--
John Carson

Jul 23 '05 #2

kelvSYC wrote:
This little bit of seeminly innocent code seems to give me these two
errors, all on the line that declares check(). Is there some part of
C++ that I'm missing out on?

class Condition {
public:
Condition() {}
virtual ~Condition() {}

virtual bool check() const;
};

class AndCondition : public Condition {
std::vector<Con dition> conditionList;

public:
AndCondition(st d::vector<Condi tion> list =
std::vector<Con dition>()) : conditionList(l ist) {}
virtual ~AndCondition() {}

std::vector<Con dition>& getConditionLis t() { return
conditionList; }
const std::vector<Con dition>& getConditionLis t() const { return
conditionList; }

bool check() const;
};

/* more classes that extend Condition here */

--
I am only a mirage.


Hi,

The code compiles without errors in VC 6.0

-vs_p...

Jul 23 '05 #3
Have you defined Condition::chec k() anywhere?? because "virtual bool
check() const;" is only a declaration. Similar for the AndCondition
class. If you do not want to define it in Condition then make it pure
by putting: virtual bool check() const = 0;

btw I copied your code to try compiling it. The following code compiled
without any problem on g++ on solaris.

#include<iostre am>
#include<vector >

class Condition {
public:
Condition() { }
virtual ~Condition() { }
virtual bool check() const;
};
class AndCondition : public Condition {
std::vector<Con dition> conditionList;

public:
AndCondition(st d::vector<Condi tion> list =
std::vector<Con dition>()) : conditionList(l ist) {}
virtual ~AndCondition() {}
std::vector<Con dition>& getConditionLis t() { return
conditionList; }
const std::vector<Con dition>& getConditionLis t() const { return
conditionList; }
bool check() const;
};

bool Condition::chec k() const
{
return 1;
}
bool AndCondition::c heck() const
{
return 1;
}

void main(){

return 0;
}
since you have not given the full code, you can find the problem by
matching your code with this.

regards,
shivank

Jul 23 '05 #4
kelvSYC wrote:
This little bit of seeminly innocent code seems to give me these two
errors, all on the line that declares check(). Is there some part of
C++ that I'm missing out on?

class Condition {
public:
Condition() {}
virtual ~Condition() {}

virtual bool check() const;
};

class AndCondition : public Condition {
std::vector<Con dition> conditionList;

public:
AndCondition(st d::vector<Condi tion> list =
std::vector<Con dition>()) : conditionList(l ist) {}
virtual ~AndCondition() {}

std::vector<Con dition>& getConditionLis t() { return
conditionList; }
const std::vector<Con dition>& getConditionLis t() const { return
conditionList; }

bool check() const;
};

/* more classes that extend Condition here */


There is nothing syntactically wrong with the code you posted (i.e. I
was able to compile it in a program without the compiler complaining).
However, there are some things that may not be doing what you want. For
your base "Condition" class, do you intend for any and all calls to
"check" to be forwarded to a derived class, or does the base class have
it's own definition somewhere as well? I suspect what you actually want
is for it to be a pure virtual function, denoted:

virtual bool check() const = 0;

Also, you are storing vectors of "Condition" objects. Presumably you
are going to iterate through those vectors and call the "check" member
of each. What you probably intend to be doing here is storing a vector
of objects derived from "Condition" , in which case you are going to need
to store pointers, rather than actual objects. That is:

std::vector<Con dition *> conditionList;

Further, storing pointers will give the polymorphic behavior you expect
from calling "check". Remember, function calls are only polymorphic if
they are made from a pointer or reference.

Alan
Jul 23 '05 #5
In article
<42************ ***********@un-2park-reader-01.sydney.pipen etworks.com.au>
, John Carson <jc************ ****@netspace.n et.au> wrote:
"kelvSYC" <ke*****@no.ema il.shaw.ca> wrote in message
news:1705200500 10511072%ke**** *@no.email.shaw .ca
This little bit of seeminly innocent code seems to give me these two
errors, all on the line that declares check(). Is there some part of
C++ that I'm missing out on?


VC++ 7.1 and Comeau both accept your code without complaint. What compiler
are you using?


gcc 3.3 on Mac OS X 10.4, under the XCode IDE.

Also to be noted that this file is a header file, and is included in
objective-c++ sources (although that shouldn't make any difference).

--
I am only a mirage.
Jul 23 '05 #6
In message <17************ ************@no .email.shaw.ca> , kelvSYC
<ke*****@no.ema il.shaw.ca> writes
In article
<42*********** ************@un-2park-reader-01.sydney.pipen etworks.com.au>
, John Carson <jc************ ****@netspace.n et.au> wrote:
"kelvSYC" <ke*****@no.ema il.shaw.ca> wrote in message
news:1705200500 10511072%ke**** *@no.email.shaw .ca
> This little bit of seeminly innocent code seems to give me these two
> errors, all on the line that declares check(). Is there some part of
> C++ that I'm missing out on?
>


VC++ 7.1 and Comeau both accept your code without complaint. What compiler
are you using?


gcc 3.3 on Mac OS X 10.4, under the XCode IDE.

Also to be noted that this file is a header file, and is included in
objective-c++ sources (although that shouldn't make any difference).

Is it possible that any of those sources (or what they include) defines
a macro called 'check' ?

--
Richard Herring
Jul 23 '05 #7

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

Similar topics

2
6387
by: Jacek Dziedzic | last post by:
Is it valid to use a "using namespace foo" (as opposed to using foo::bar which I'm sure is legal) within a class declaration? My compiler rejects it, but I've been told it's valid. Can anyone please confirm or deny? TIA, - J.
3
8867
by: Robert | last post by:
---EN--- This message has been crossposted in a french speaking newsgroup, english version is at the end. Thanks a lot for your help... --/EN--- Bonjour, Je développe une application intranet qui "tourne" maintenant depuis plusieurs années auprès de 2500 personnes environ, mais depuis 1 mois,
175
8767
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be changed". This is very much against my instincts. Can anyone offer some solid design guidelines for me? Thanks in advance....
1
3463
by: Bart Simpson | last post by:
Can anyone explain the concept of "slicing" with respect to the "virtual constructor" idiom as explain at parashift ? From parashift: class Shape { public: virtual ~Shape() { } // A virtual destructor
0
8213
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
8156
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
8653
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
8457
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...
1
6101
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4065
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
2587
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
1460
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.