473,413 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

regarding static fn

Hi ,
A static member can be accessed only by another static method....but the
vice-versa is not true....Can anyone pls explain me the logic behind this...

Also in a project, if we have too many static members and methods, will it
cause a problem??

thanx for ur comments
regards,
Raghavendra Mahuli
Jul 22 '05 #1
4 1938
What i mean by vice versa....
A static method can access non static members
"raghavendra" <ra************@in.bosch.com> wrote in message
news:c2**********@ns1.fe.internet.bosch.com...
Hi ,
A static member can be accessed only by another static method....but the
vice-versa is not true....Can anyone pls explain me the logic behind this...
Also in a project, if we have too many static members and methods, will it cause a problem??

thanx for ur comments
regards,
Raghavendra Mahuli

Jul 22 '05 #2
On Tue, 2 Mar 2004 18:31:30 +0530, "raghavendra"
<ra************@in.bosch.com> wrote:
What i mean by vice versa....
A static method can access non static members
"raghavendra" <ra************@in.bosch.com> wrote in message
news:c2**********@ns1.fe.internet.bosch.com...
Hi ,
A static member can be accessed only by another static method....but the
vice-versa is not true....Can anyone pls explain me the logic behind

this...

Also in a project, if we have too many static members and methods, will

it
cause a problem??

thanx for ur comments
regards,
Raghavendra Mahuli


A static member function cannot access non-static members using
/unqualified names/, but it can if those the names are qualified (by dot
(.), arrow (->) or ::) (in the same way those members would be accessed
from code in a non-member function such as main()).

The thing to remember is that unqualified names within a member function
that resolve to non-static members of the same class act as if they were
preceded by "this->", implying that each instantiated object of the class
has its own copy of the data (or that it makes sense to call a member
function that requires a "this" object to operate upon).

A static member function has no "this" object, so it wouldn't make much
sense for code within such a function to say something like
int i = length();
meaning:
int i = this->length();
if there's no implicit object to apply the length() function to. So that
isn't allowed.

On the other side of the coin, within a /non-static/ member function, all
uses of unqualified static member names refer, by definition, to the same
object...although it makes equally little sense to /qualify/ these names
with . or -> or :: (well, the latter could make sense to force a
non-default scope resolution), C++ allows them all just so we all have
more options for creating cryptic code ;-)
-leor


Leor Zolman
BD Software
le**@bdsoft.com
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3
Thanx leor for the info.
I would also like to know why a static member can be accessed only by a
STATIC member function

What i mean by vice versa....
A static method can access non static members
On the other side of the coin, within a /non-static/ member function, all
uses of unqualified static member names refer, by definition, to the same
object...although it makes equally little sense to /qualify/ these names
with . or -> or :: (well, the latter could make sense to force a
non-default scope resolution), C++ allows them all just so we all have
more options for creating cryptic code ;-)
-leor

Jul 22 '05 #4
On Thu, 4 Mar 2004 11:01:01 +0530, "raghavendra"
<ra************@in.bosch.com> wrote:
Thanx leor for the info.
I would also like to know why a static member can be accessed only by a
STATIC member function
But that's not the case. The only place the word "only" applies is here: a
non-static member can **only** be accessed--via an /unqualified/
call--from within a member function (as I explained earlier).

As the paragraph I wrote (which you quote below) says. A "non-static member
function" (the OPPOSITE of a "static member function"), can access statics
just fine...and regardless of what the "this" object is during such a call,
any access to a static member named "x" will yield the exact same singular
member whether you write the expressions as
x
or
this->x
or
(*this).x
or
classname::x

At this point, I highly suggest you just start writing some code to try out
the permutations. It should then make a lot more sense (like anything in
programming.)

Good luck,
-leor


>What i mean by vice versa....
>A static method can access non static members

On the other side of the coin, within a /non-static/ member function, all
uses of unqualified static member names refer, by definition, to the same
object...although it makes equally little sense to /qualify/ these names
with . or -> or :: (well, the latter could make sense to force a
non-default scope resolution), C++ allows them all just so we all have
more options for creating cryptic code ;-)
-leor


Leor Zolman
BD Software
le**@bdsoft.com
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
2
by: djinni | last post by:
howdy, Can anyone tell me where the function name string is stored when __func__ is used? I read that it is basically like declaring a static const char, but when I compile the following code,...
9
by: sonu | last post by:
Hi All, Pls clarify me what is the difference between static member and static method in c. pls some one reply me with Example.
2
by: John Smith | last post by:
Hi, I have a question regarding the initialisation of aggregates: The C (99) standard states: section 6.7.8, paragraph 21 states: If there are fewer initializers in a brace-enclosed list than...
2
by: Suresh Kumar Rathod | last post by:
HI friends... Can any body give reason / logic behind static varable lifetime through out the process execution. i.e how does compiler maintains the static varable life through out the process...
2
by: palani12kumar | last post by:
can you please clear my doubt regarding static variables? at the time of declaring a static variable, is it compulsary to declare its data type? that is.... instead of writing "static int a;",...
1
by: wizwx | last post by:
I just noticed an interesting implementation of Singleton from Bruce Eckel's "Thinking in C++" vol. 2, pp 620: class Singleton { static Singleton s; public: static Singleton& instance() {...
8
by: somenath | last post by:
Hi All, I have a doubt regarding the pointer assignment . Please have a look at the following program . #include<stdio.h> #include<stdlib.h> #define NAMESIZE 10 #define SAFE_FREE(t) if(t)\...
1
by: subhalalitha | last post by:
There is a requirement in our system. There is one Transaction Monitoring thread which wakes up after every 30 sec and checks for the requests that didnot get responses for "2 min" and sends...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.