473,388 Members | 897 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,388 software developers and data experts.

"virtual outside class declaration" and "declaration 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<Condition> conditionList;

public:
AndCondition(std::vector<Condition> list =
std::vector<Condition>()) : conditionList(list) {}
virtual ~AndCondition() {}

std::vector<Condition>& getConditionList() { return
conditionList; }
const std::vector<Condition>& getConditionList() const { return
conditionList; }

bool check() const;
};

/* more classes that extend Condition here */

--
I am only a mirage.
Jul 23 '05 #1
6 9706
"kelvSYC" <ke*****@no.email.shaw.ca> wrote in message
news:170520050010511072%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<Condition> conditionList;

public:
AndCondition(std::vector<Condition> list =
std::vector<Condition>()) : conditionList(list) {}
virtual ~AndCondition() {}

std::vector<Condition>& getConditionList() { return
conditionList; }
const std::vector<Condition>& getConditionList() 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<Condition> conditionList;

public:
AndCondition(std::vector<Condition> list =
std::vector<Condition>()) : conditionList(list) {}
virtual ~AndCondition() {}

std::vector<Condition>& getConditionList() { return
conditionList; }
const std::vector<Condition>& getConditionList() 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::check() 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<iostream>
#include<vector>

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

public:
AndCondition(std::vector<Condition> list =
std::vector<Condition>()) : conditionList(list) {}
virtual ~AndCondition() {}
std::vector<Condition>& getConditionList() { return
conditionList; }
const std::vector<Condition>& getConditionList() const { return
conditionList; }
bool check() const;
};

bool Condition::check() const
{
return 1;
}
bool AndCondition::check() 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<Condition> conditionList;

public:
AndCondition(std::vector<Condition> list =
std::vector<Condition>()) : conditionList(list) {}
virtual ~AndCondition() {}

std::vector<Condition>& getConditionList() { return
conditionList; }
const std::vector<Condition>& getConditionList() 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<Condition *> 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.pipenetworks.com.au>
, John Carson <jc****************@netspace.net.au> wrote:
"kelvSYC" <ke*****@no.email.shaw.ca> wrote in message
news:170520050010511072%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.email.shaw.ca> writes
In article
<42***********************@un-2park-reader-01.sydney.pipenetworks.com.au>
, John Carson <jc****************@netspace.net.au> wrote:
"kelvSYC" <ke*****@no.email.shaw.ca> wrote in message
news:170520050010511072%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
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...
3
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...
175
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...
1
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() { } ...
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: 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: 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...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.