illegal reference to non-static member

  • Thread starter Gabrielle A. Grün
  • Start date
G

Gabrielle A. Grün

Hi All,

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

member? Thanks.



iNHERITANCE HIERACY

TestInherit TestInherit

| |

| |

TestInheritChild TestInheritG

|

|

TestInheritGChild



///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 TestInheritChild : public TestInherit {

public:

// Default Constructor

TestInheritChild ();

// Copy constructor

TestInheritChild ( const TestInheritChild &);

// Assignment operator

TestInheritChild & operator=( const TestInheritChild& rhs);

/// Destructor

virtual ~TestInheritChild();

private:

int * intP_;

};

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

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

#include "TestInherit.hpp"

// Default Constructor

TestInherit::TestInherit()

:

{

}



// Destructor

TestInherit::~TestInherit ()

{

}

// Copy constructor

TestInherit::TestInherit ( const TestInherit & rhs)

{

}

// Assignment operator

TestInherit &

TestInherit::eek:perator=( const TestInherit& rhs)

{

if (this!=&rhs) {


}

return *this;

}




// Default Constructor

TestInheritChild::TestInheritChild()

: intP_(NULL),

{

}



// Destructor

TestInheritChild::~TestInheritChild ()

{

delete intP_;

}

// Copy constructor

TestInheritChild::TestInheritChild ( const TestInheritChild & rhs)

{


}

// Assignment operator

TestInheritChild &

TestInheritChild::eek:perator=( const TestInheritChild& rhs)

{

if (this!=&rhs) {


}

return *this;

}

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

////////////// TestInheritG.hpp

#include "TestInherit.hpp"

class TestInheritG : public TestInherit {

public:

// Default Constructor

TestInheritG ();



// Copy constructor

TestInheritG ( const TestInheritG &);

// Assignment operator

TestInheritG & operator=( const TestInheritG& rhs);

/// Destructor

virtual ~TestInheritG();




};





class TestInheritGChild : public TestInheritG {

public:

// Default Constructor

TestInheritGChild ();



// Copy constructor

TestInheritGChild ( const TestInheritGChild &);


// Assignment operator

TestInheritGChild & operator=( const TestInheritGChild& rhs);

/// Destructor

virtual ~TestInheritGChild();


private:

int * intP_;

}

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

/////TestInheritG.cpp

#include "TestInheritG.hpp"

// Default Constructor

TestInheritG::TestInheritG()

:

{

}



// Destructor

TestInheritG::~TestInheritG ()

{

}

// Copy constructor

TestInheritG::TestInheritG ( const TestInheritG & rhs)

{

}

// Assignment operator

TestInheritG &

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

{

if (this!=&rhs) {

}

return *this;

}





//ttester

int TestInheritG::tester ( double index)

{

return (int) index;

}



// Default Constructor

TestInheritGChild::TestInheritGChild()

:intP_(NULL),

{

}



// Destructor

TestInheritGChild::~TestInheritGChild ()

{

int newInt=*intP_;

TestInheritChild::intP_=&newInt; ///////////TH ERROR POINT
///////////////////////

delete intP_;

}

// Copy constructor

TestInheritGChild::TestInheritGChild ( const TestInheritGChild & rhs)

{

}

// Assignment operator

TestInheritGChild &

TestInheritGChild::eek:perator=( const TestInheritGChild& rhs)

{

if (this!=&rhs) {

}

return *this;

}




=--------\

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

Win32 ------

Compiling...

TestInheritG.cpp

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

'TestInheritChild::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>
 
T

Thomas Jakob

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi All,

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

member? Thanks.

<snip a lot of code>

Please post only a minimal example. Nobody cares about so much code.
TestInheritG.cpp(__) : error C2597: illegal reference to non-static member

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)

iD8DBQFDvyJZbpGyJtILqbcRAl2cAJ9sfOqvZAnPduCagtYftdN9f0uD/gCeOTsD
rcdIRLQjNgP1qt9mdKoIJ1Q=
=gFPt
-----END PGP SIGNATURE-----
 
D

David Harmon

On Sat, 07 Jan 2006 01:37:21 GMT in comp.lang.c++, "Gabrielle A.
Grün said:
// Destructor
TestInheritGChild::~TestInheritGChild ()
{
int newInt=*intP_;
TestInheritChild::intP_=&newInt; ///////////TH ERROR POINT

Well, yes. Where is that assignment supposed to find an instance of
TestInheritChild upon which to do it's foul deed? What instance of
TestInheritChild is ibtP_ a part of? TestInheritGChild 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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top