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

Discussion in 'C++' started by kelvSYC, May 17, 2005.

  1. kelvSYC

    kelvSYC Guest

    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.
    kelvSYC, May 17, 2005
    #1
    1. Advertising

  2. kelvSYC

    John Carson Guest

    "kelvSYC" <> wrote in message
    news:170520050010511072%
    > 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
    John Carson, May 17, 2005
    #2
    1. Advertising

  3. kelvSYC

    Achintya Guest

    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...
    Achintya, May 17, 2005
    #3
  4. kelvSYC

    shivank Guest

    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
    shivank, May 17, 2005
    #4
  5. kelvSYC

    Alan Johnson Guest

    Re: "virtual outside class declaration" and "declaration does notdeclare anything"

    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
    Alan Johnson, May 17, 2005
    #5
  6. kelvSYC

    kelvSYC Guest

    In article
    <428999f9$0$27865$>
    , John Carson <> wrote:

    > "kelvSYC" <> wrote in message
    > news:170520050010511072%
    > > 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.
    kelvSYC, May 17, 2005
    #6
  7. In message <170520050133228128%>, kelvSYC
    <> writes
    >In article
    ><428999f9$0$27865$>
    >, John Carson <> wrote:
    >
    >> "kelvSYC" <> wrote in message
    >> news:170520050010511072%
    >> > 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
    Richard Herring, May 17, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nut Cracker
    Replies:
    1
    Views:
    338
  2. jakk
    Replies:
    4
    Views:
    12,118
  3. titi

    if and and vs if and,and

    titi, Mar 9, 2007, in forum: VHDL
    Replies:
    4
    Views:
    578
    Mike Treseler
    Mar 11, 2007
  4. prix prad

    Declaration does not declare anything error

    prix prad, Oct 1, 2009, in forum: C Programming
    Replies:
    6
    Views:
    4,019
    Andrey Tarasevich
    Oct 2, 2009
  5. prix prad

    Declaration does not declare anything error

    prix prad, Oct 1, 2009, in forum: C Programming
    Replies:
    0
    Views:
    274
    prix prad
    Oct 1, 2009
Loading...

Share This Page