By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

illegal reference to non-static member

P: n/a


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::operator=( 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::operator=( 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::operator=( 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::operator=( 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>
Jan 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gabrielle A. Grün wrote:
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)

iD8DBQFDvyJZbpGyJtILqbcRAl2cAJ9sfOqvZAnPduCagtYftd N9f0uD/gCeOTsD
rcdIRLQjNgP1qt9mdKoIJ1Q=
=gFPt
-----END PGP SIGNATURE-----
Jan 7 '06 #2

P: n/a
On Sat, 07 Jan 2006 01:37:21 GMT in comp.lang.c++, "Gabrielle A.
Grün" <gr**@cs.sfu.ca> wrote,
// 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?

Jan 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.