470,827 Members | 1,724 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,827 developers. It's quick & easy.

using extern to declare an instance of a class.

Say there are two classes: System_Controller_Class and UDP_Input_Class.

If I were to declare an instance of class UDP_Input_Class in
System_Controller_Class like so:

extern UDP_Input_Class UDP_Input;

what would be the significance? why not just declare an instance of
the class without the extern? What does adding the extern buy you in
terms of scope?

May 12 '06 #1
1 2571
* kid_kei:
Say there are two classes: System_Controller_Class and UDP_Input_Class.

If I were to declare an instance of class UDP_Input_Class in
System_Controller_Class like so:

extern UDP_Input_Class UDP_Input;

what would be the significance?
Depends on where that declaration occurs.

For a member variable a conforming compiler must reject the code: you
don't use "extern" for member variables.

For a variable declared locally in a member function, it would be a
declaration of an "extern" variable at namespace scope, i.e. a global
variable -- defined somewhere else (most probably in another
translation unit).

why not just declare an instance of the class without the extern?
Only you can answer why you would add "extern".

What does adding the extern buy you in terms of scope?


See above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Gernot Frisch | last post: by
4 posts views Thread by John Ratliff | last post: by
29 posts views Thread by DevarajA | last post: by
5 posts views Thread by Christian Christmann | last post: by
3 posts views Thread by coder | last post: by
2 posts views Thread by Sunil Varma | last post: by
14 posts views Thread by raylopez99 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.