473,378 Members | 1,470 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,378 software developers and data experts.

C++ static function

Hi,
How can we create a effect of C++ static function without using
the keyword static?

Thanks ...

Sep 11 '06 #1
8 2169
How can we create a effect of C++ static function without using
the keyword static?

Google for "anonymous namespace".

--

Frederick Gotham
Sep 11 '06 #2
pr*****@yahoo.com wrote:
How can we create a effect of C++ static function without using
the keyword static?
Which effect is that?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 11 '06 #3
prsu...@yahoo.com wrote:
How can we create a effect of C++ static function without using
the keyword static?
Do you mean, how can you get a member function of an object
to be like a static without using the keyword static?

If so, you can't. Member functions have an implied "this" that
tells the function what instance of the class is being called.

There are ways to "get around" this, depending on what your
context is. What are you trying to do?
Socks

Sep 11 '06 #4
Frederick Gotham wrote:
> How can we create a effect of C++ static function without using
the keyword static?


Google for "anonymous namespace".
Try not to do somebody's homework here, will you?
Sep 11 '06 #5
Victor Bazarov posted:
>Google for "anonymous namespace".

Try not to do somebody's homework here, will you?

If that's a homework question, then the teacher is incompetant.

"Hi, today I'm going to teach you about transmissions. Your homework is to go
find out how transmissions work."

--

Frederick Gotham
Sep 11 '06 #6
Frederick Gotham wrote:
Victor Bazarov posted:
>>Google for "anonymous namespace".

Try not to do somebody's homework here, will you?


If that's a homework question, then the teacher is incompetant.
I thought it was difficult to find somebody with a quicker judgment
on Usenet than myself... The teacher is not incompetent by giving
such homework assignments. The student is definitely lazy if he
tries to get the answer instead of researching it.

Besides, it could be a homework not given by a teacher; it looks
very much like an interview question from one of those "get ready
to be a C++ programmer by answering all those interview questions"
sites.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 11 '06 #7
Victor Bazarov posted:
Besides, it could be a homework not given by a teacher; it looks
very much like an interview question from one of those "get ready
to be a C++ programmer by answering all those interview questions"
sites.

Maybe I'm narrow-minded, but here's an analogy that crept into my head:

Imagine I have a 4 year old son. He comes home from school one day and
asks me, "Daddy, what letter comes after G in the alphabet? Our teacher
told us to go find out.". Do I:

(a) Deem the teacher to be great for making the children go out and
learn things for themselves.

or:

(b) Scorn the teacher for not teaching my son the alphabet.

A teacher's job is to teach, not to instruct the student to go off and
figure things out for themselves. When I was at school, I had many
incompetant teachers (one of the perks of growing up in a working-class
area -- although I could never quite understand why they call it working-
class if the people don't actually work...) who regularly didn't teach, and
instead instructed the students to go off and learn things for themselves.
Result? Well it seems a little inconsistent that after 6 years of high
school, I'm fluent in one of the human languages I learned, and can't
string a sentence together in the other.

Don't tell a student, "Go off an figure out how we implement internal
linkage in C++". At the VERY least, instruct them to Google for "anonymous
namespace".

--

Frederick Gotham
Sep 11 '06 #8
Frederick Gotham wrote:
[...]
Imagine I have a 4 year old son. He comes home from school one day
and asks me, "Daddy, what letter comes after G in the alphabet? Our
teacher told us to go find out.". Do I:

(a) Deem the teacher to be great for making the children go out and
learn things for themselves.

or:

(b) Scorn the teacher for not teaching my son the alphabet.
Huh? Ever heard of "tests"? First you teach, then you ask to perform
a task to see how well the pupil has absorbed the material.

How is giving a task to do something relatively simple negates the
possibility that it _has_ been taught, in your mind?
[...nonsensical complaint about a bad school attended removed...]
We all went to bad schools. Doesn't mean there aren't normal schools
out there.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 11 '06 #9

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

Similar topics

1
by: Jean-Francois Brault | last post by:
I wrote a crappy class for radian angle management. The class consists of an array of radian values. I put all these things in a class in which all methods are static, so I can access it anywhere...
6
by: Dumitru Sipos | last post by:
Hello everybody! is there possible to have a function that is both static and virtual? Dumi.
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
5
by: Tony Johansson | last post by:
Hello experts! Why is not possible to have virtual static members Many thnakn //Tony
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
32
by: lcdgoncalves | last post by:
Hi everyone Is there a real need to use keyword static with functions, if we simply don't declare their prototypes in .h file? Many textbooks avoid to discuss this matter and/or discuss only...
1
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.