473,396 Members | 2,036 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,396 software developers and data experts.

Namespace Scope functions and the static keyword in CLI

Hi,

I have an interesting issue, well, it's not really an issue, but I'd
like to understand the mechanics of what's going on. I have a file,
in CLI, which has a class declared, and a static fuction. Because the
class is declared globally, I declare it as static.

Is a function with a namespace scope declared as static by default?

So, this worked fine when I was accessing the static function inside
the cpp file paired with this header. Keep in mind that it is
declared static explicitly.

But when I ty to access this static function from another file, aside
from the cpp file the class is implemented in, I get an compile error
C2129 function declared but not defined. But when declare it as
static inline, or remove the static keyword it works fine.

Can someone explain why this is?

May 21 '07 #1
2 3132
>But when I ty to access this static function from another file, aside
>from the cpp file the class is implemented in, I get an compile error
when applied to a global function, the static keyword limits the scope
to the current source module, so an error in that circumstance is to
be expected.
>But when declare it as
static inline, or remove the static keyword it works fine.
If you define it inline (in the header file), both source modules will
have a copy of the code.

Dave
May 21 '07 #2

"David Lowndes" <Da****@example.invalidwrote in message
news:ku********************************@4ax.com...
But when I ty to access this static function from another file, aside
from the cpp file the class is implemented in, I get an compile error

when applied to a global function, the static keyword limits the scope
to the current source module, so an error in that circumstance is to
be expected.
And because this behavior is inconsistent with other uses of static, it's
now recommended to use the anonymous namespace for that instead.
>
>>But when declare it as
static inline, or remove the static keyword it works fine.
Without the static keyword, you should have gotten a multiple definition
error.
>
If you define it inline (in the header file), both source modules will
have a copy of the code.
Inline functions should be defined in the header file, non-inline function
should have a prototype in the header, but the definition should always be
in an implementation file. This is based on your use of the inline keyword
(or defining inside the type declaration), not the compiler's ultimate
decision whether to inline or not.
>
Dave

May 22 '07 #3

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

Similar topics

3
by: Anonymous | last post by:
Is namespace the same thing as scope? While reading the book "Thinking in C++", I was under the impression that namespace is, well, a namespace--a feature to create a hiearchy for identifiers...
7
by: ark | last post by:
Hi, If I got it right, C++ deprecates using 'static' keyword for internal linkage in favor of a namespace. I don't understand the equivalence though: namespace assignment does not mechanically...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
4
by: Peter Ammon | last post by:
I would like to share a variable between two functions defined in two separate source files; no other functions will need the global variable so I'd prefer to not give it file scope. Thus, I want...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
32
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
3
by: mackenzie | last post by:
I was wondering why it is "ill-formed if an allocation function is declared in a namespace"? I have done some searching on the web and can not find a reason why; I have stumbled across a few other...
22
by: Luna Moon | last post by:
I am reading the book "C++ Annotations", and here is a quote from the book: Namespaces can be defined without a name. Such a namespace is anonymous and it restricts the visibility of the...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...

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.