473,473 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

| |

| |

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
2 17339
-----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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Ney André de Mello Zunion | last post by:
Hello. Binding a temporary to a non-const reference is illegal. Everybody should be tired of hearing that. So should I. But then I found myself wondering about a small piece of code I was...
4
by: qazmlp | last post by:
// Test.C Line-300: namespace Line-301: { Line-302: std::vector<std::string> vecaNS ; Line-303: } The 'SUN Forte 7 C++ Compiler' reports the following warning for the above code:...
17
by: johny smith | last post by:
I never really know if I should use references or pointers for constructors. Can anyone give me some guidance on when to use what? My back ground is C, so I tend to use pointer notation, but...
6
by: Senthilvel | last post by:
Hi folks, My friend tells that the following function declaration is illegal. void Foo(const string& strData = "Default"); My friend argues that it is not legal to provide a default value for...
10
by: JKop | last post by:
Firstly, we all know that temporaries are non-const, which I shall demonstrate with the following code: struct Blah { int monkey; void SetMonkey(int const supplied) { monkey = supplied;
28
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue...
5
by: Oleg Subachev | last post by:
When I try to use strongly named assembly1 that references non-strongly named assembly2 I get the following error: "The located assembly '<assembly2 name>' is not strongly named." How can I...
9
by: Roshni | last post by:
Hi, I wanted to know how do function pointers sometime access illegal memory access ? Could any one give me an example ? Thanks, Roshni
21
by: Andrew Ward | last post by:
Consider the following: #include <iostream> struct X { int x; X() { x = 6; } };
11
by: tthunder | last post by:
Hi @all, My small example does not compile... I know, that this (as always) has reasons, but I want to know WHY? BTW: I only get errors with g++ (4.x), BCB (6.0),... VS C++ (2005) works...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.