Thread View: comp.std.c++
3 messages
3 total messages
Started by scott douglass
Thu, 14 Mar 1996 16:17
No way to define some extern consts?
Author: scott douglass
Date: Thu, 14 Mar 1996 16:17
Date: Thu, 14 Mar 1996 16:17
25 lines
1443 bytes
1443 bytes
Hello all,
Given a class type with only a no-argument contstrutor:
struct T { T(); /* ... */ }; // assume no other ctors
Is there any way to define an extern const object of class T?
extern const T t; // nope: this is a declaration
const T t2; // nope: this is a definition, but t2 is not extern
extern const T t3(); // nope: this is a declaration of the function
named t3 which returns a const T
So, can you find a way to *define* an extern const object type T?
(Besides adding some ctor with a dummy argument.) If you can you9re
smarter than I am.
Thanks,
--scott
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: No way to define some extern consts?
Author: Harlan Messinger
Date: Fri, 15 Mar 1996 07:40
Date: Fri, 15 Mar 1996 07:40
29 lines
1695 bytes
1695 bytes
scott douglass (sdouglas@armltd.co.uk) wrote:
: Hello all,
:
: Given a class type with only a no-argument contstrutor:
:
: struct T { T(); /* ... */ }; // assume no other ctors
:
: Is there any way to define an extern const object of class T?
:
: extern const T t; // nope: this is a declaration
: const T t2; // nope: this is a definition, but t2 is not extern
This is the correct one. The object ISN'T external from the point of view
of the module in which it's defined! You'll declare
extern const T t2;
in the header file, but define
const T t2;
as a global non-static object in the one source file in which you want it
to reside.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: No way to define some extern consts?
Author: scott douglass
Date: Fri, 15 Mar 1996 13:16
Date: Fri, 15 Mar 1996 13:16
38 lines
2005 bytes
2005 bytes
In article <4iat2h$pk5@clarknet.clark.net>, gusty@clark.net (Harlan
Messinger) wrote:
: scott douglass (sdouglas@armltd.co.uk) wrote:
: : Hello all,
: :
: : Given a class type with only a no-argument contstrutor:
: :
: : struct T { T(); /* ... */ }; // assume no other ctors
: :
: : Is there any way to define an extern const object of class T?
:[...]
: You'll declare
:
: extern const T t2;
:
: in the header file, but define
:
: const T t2;
:
: as a global non-static object in the one source file in which you want it
: to reside.
Thanks. As you mention and Geert-Jan Giezeman pointed out in private
e-mail, the key here is that the definition can be accomplished by having
both and extern declaration and a definition the same translation unit:
extern const T t; // declaration
const T t; // definition, still extern
You can't do it in one declaration but it's not hard after all.
--scott
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads