Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "virtual outside class declaration" and "declaration does not declare anything"

Reply
Thread Tools

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

 
 
kelvSYC
Guest
Posts: n/a
 
      05-17-2005
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.
 
Reply With Quote
 
 
 
 
John Carson
Guest
Posts: n/a
 
      05-17-2005
"kelvSYC" <(E-Mail Removed)> wrote in message
news:170520050010511072%(E-Mail Removed)
> 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

 
Reply With Quote
 
 
 
 
Achintya
Guest
Posts: n/a
 
      05-17-2005

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...

 
Reply With Quote
 
shivank
Guest
Posts: n/a
 
      05-17-2005
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

 
Reply With Quote
 
Alan Johnson
Guest
Posts: n/a
 
      05-17-2005
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
 
Reply With Quote
 
kelvSYC
Guest
Posts: n/a
 
      05-17-2005
In article
<428999f9$0$27865$(E-Mail Removed)>
, John Carson <(E-Mail Removed)> wrote:

> "kelvSYC" <(E-Mail Removed)> wrote in message
> news:170520050010511072%(E-Mail Removed)
> > 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.
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      05-17-2005
In message <170520050133228128%(E-Mail Removed)>, kelvSYC
<(E-Mail Removed)> writes
>In article
><428999f9$0$27865$(E-Mail Removed)>
>, John Carson <(E-Mail Removed)> wrote:
>
>> "kelvSYC" <(E-Mail Removed)> wrote in message
>> news:170520050010511072%(E-Mail Removed)
>> > 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
 
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
micro to declare and initialize a struct pointer does not work, why? KOFKS C Programming 5 03-04-2009 01:03 PM
private forward declare, public class. What does the standard say? Daniel T. C++ 1 01-20-2009 12:50 AM
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
Decralation of class inside other class and definition outside this class =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki C++ 2 07-12-2007 11:52 PM
declare variable inside or outside block? Angus Parvis Java 14 01-02-2005 06:32 PM



Advertisments