472,118 Members | 1,216 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,118 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 9408
"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 discussion thread is closed

Replies have been disabled for this discussion.

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.