illegal reference to non-static member

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabrielle  A. Grün

    illegal reference to non-static member



    Hi All,

    Does anyone know a way around the illegal reference of a non-static

    member? Thanks.



    iNHERITANCE HIERACY

    TestInherit TestInherit

    | |

    | |

    TestInheritChil d TestInheritG

    |

    |

    TestInheritGChi ld



    ///TestInherit.hpp

    #include <string>

    #include <vector>

    class TestInherit {

    public:

    // Default Constructor

    TestInherit ();



    // Copy constructor

    TestInherit ( const TestInherit &);

    // Assignment operator

    TestInherit & operator=( const TestInherit& rhs);

    /// Destructor

    virtual ~TestInherit();

    ;



    class TestInheritChil d : public TestInherit {

    public:

    // Default Constructor

    TestInheritChil d ();

    // Copy constructor

    TestInheritChil d ( const TestInheritChil d &);

    // Assignment operator

    TestInheritChil d & operator=( const TestInheritChil d& rhs);

    /// Destructor

    virtual ~TestInheritChi ld();

    private:

    int * intP_;

    };

    //////////////------------------------

    ///////// TestInherit.cpp

    #include "TestInherit.hp p"

    // Default Constructor

    TestInherit::Te stInherit()

    :

    {

    }



    // Destructor

    TestInherit::~T estInherit ()

    {

    }

    // Copy constructor

    TestInherit::Te stInherit ( const TestInherit & rhs)

    {

    }

    // Assignment operator

    TestInherit &

    TestInherit::op erator=( const TestInherit& rhs)

    {

    if (this!=&rhs) {


    }

    return *this;

    }




    // Default Constructor

    TestInheritChil d::TestInheritC hild()

    : intP_(NULL),

    {

    }



    // Destructor

    TestInheritChil d::~TestInherit Child ()

    {

    delete intP_;

    }

    // Copy constructor

    TestInheritChil d::TestInheritC hild ( const TestInheritChil d & rhs)

    {


    }

    // Assignment operator

    TestInheritChil d &

    TestInheritChil d::operator=( const TestInheritChil d& rhs)

    {

    if (this!=&rhs) {


    }

    return *this;

    }

    -///////////////////////////--------------------

    ////////////// TestInheritG.hp p

    #include "TestInherit.hp p"

    class TestInheritG : public TestInherit {

    public:

    // Default Constructor

    TestInheritG ();



    // Copy constructor

    TestInheritG ( const TestInheritG &);

    // Assignment operator

    TestInheritG & operator=( const TestInheritG& rhs);

    /// Destructor

    virtual ~TestInheritG() ;




    };





    class TestInheritGChi ld : public TestInheritG {

    public:

    // Default Constructor

    TestInheritGChi ld ();



    // Copy constructor

    TestInheritGChi ld ( const TestInheritGChi ld &);


    // Assignment operator

    TestInheritGChi ld & operator=( const TestInheritGChi ld& rhs);

    /// Destructor

    virtual ~TestInheritGCh ild();


    private:

    int * intP_;

    }

    ////////////////;============== ============

    /////TestInheritG.cp p

    #include "TestInheritG.h pp"

    // Default Constructor

    TestInheritG::T estInheritG()

    :

    {

    }



    // Destructor

    TestInheritG::~ TestInheritG ()

    {

    }

    // Copy constructor

    TestInheritG::T estInheritG ( const TestInheritG & rhs)

    {

    }

    // Assignment operator

    TestInheritG &

    TestInheritG::o perator=( const TestInheritG& rhs)

    {

    if (this!=&rhs) {

    }

    return *this;

    }





    //ttester

    int TestInheritG::t ester ( double index)

    {

    return (int) index;

    }



    // Default Constructor

    TestInheritGChi ld::TestInherit GChild()

    :intP_(NULL),

    {

    }



    // Destructor

    TestInheritGChi ld::~TestInheri tGChild ()

    {

    int newInt=*intP_;

    TestInheritChil d::intP_=&newIn t; ///////////TH ERROR POINT
    ///////////////////////

    delete intP_;

    }

    // Copy constructor

    TestInheritGChi ld::TestInherit GChild ( const TestInheritGChi ld & rhs)

    {

    }

    // Assignment operator

    TestInheritGChi ld &

    TestInheritGChi ld::operator=( const TestInheritGChi ld& rhs)

    {

    if (this!=&rhs) {

    }

    return *this;

    }




    =--------\

    ------ Build started: Project: xxxxx, Configuration: Debug

    Win32 ------

    Compiling...

    TestInheritG.cp p

    TestInheritG.cp p(__) : error C2597: illegal reference to non-static member

    'TestInheritChi ld::intP_'

    TestInherit.cpp

    Generating Code...



    ---------------------- Done ----------------------

    Gabrielle A. Grün, Ph.D. Student

    School of Computing Science

    Simon Fraser University

    8888 University Drive

    Burnaby, BC

    V5A 1S6

    <http://www.cs.sfu.ca/~grun>


  • Thomas Jakob

    #2
    Re: illegal reference to non-static member

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Gabrielle A. Grün wrote:[color=blue]
    > Hi All,
    >
    > Does anyone know a way around the illegal reference of a non-static
    >
    > member? Thanks.
    >[/color]

    <snip a lot of code>

    Please post only a minimal example. Nobody cares about so much code.
    [color=blue]
    >
    > TestInheritG.cp p(__) : error C2597: illegal reference to non-static member
    >[/color]

    Visual C++ Concepts: Building a C/C++ Program
    Compiler Error C2597

    Error Message
    illegal reference to non-static member 'identifier'

    Possible causes:

    1. A nonstatic member is specified in a static member function. To
    access the nonstatic member, you must create an instance of the class
    and use a member-access operator (. or ->).
    2. The specified identifier is not a member of a class, structure, or union.
    3. A member access operator refers to a nonmember function.
    4. The following sample generates C2597: (see
    http://msdn2.microsoft.com/library/422tf4a2.aspx)


    - --
    Greetings, Thomas Jakob
    quicix (at) gmail (dot) com
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (MingW32)

    iD8DBQFDvyJZbpG yJtILqbcRAl2cAJ 9sfOqvZAnPduCag tYftdN9f0uD/gCeOTsD
    rcdIRLQjNgP1qt9 mdKoIJ1Q=
    =gFPt
    -----END PGP SIGNATURE-----

    Comment

    • David Harmon

      #3
      Re: illegal reference to non-static member

      On Sat, 07 Jan 2006 01:37:21 GMT in comp.lang.c++, "Gabrielle A.
      Grün" <grun@cs.sfu.ca > wrote,[color=blue]
      >// Destructor
      >TestInheritGCh ild::~TestInher itGChild ()
      >{
      >int newInt=*intP_;
      >TestInheritChi ld::intP_=&newI nt; ///////////TH ERROR POINT[/color]

      Well, yes. Where is that assignment supposed to find an instance of
      TestInheritChil d upon which to do it's foul deed? What instance of
      TestInheritChil d is ibtP_ a part of? TestInheritGChi ld has no such
      instance; all you have is the class name.

      Even if you could, it would still be wrong. Saving a pointer to an
      auto variable? Mucking with another class's variables? Yeech.

      Why?

      Comment

      Working...