digitalmars.D - typeid of surrounding class from a static function?
- J Arrizza (23/23) Nov 06 2011 Hi,
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (3/26) Nov 06 2011 Considering the class is statically known, typeid(SomeClass)?
- J Arrizza (6/8) Nov 06 2011 Sorry, my simplified example simplified too far. I'd like to put the cal...
- =?utf-8?Q?Simen_Kj=C3=A6r=C3=A5s?= (13/35) Nov 06 2011 Have you tried using this? It seems to work for me:
- Andrei Alexandrescu (3/6) Nov 06 2011 typeof(this) works inside static methods too.
- Steven Schveighoffer (7/13) Nov 07 2011 More info:
Hi, I'm trying to get the name of the surrounding class from within a static method of the class: import std.stdio; void main(string[] args) { auto o = new SomeClass(); o.Run(); SomeClass.StaticRun(); } class SomeClass { public void Run() { writeln("In Class non-static: ", typeid(typeof(this))); } public static void StaticRun() { writeln("In Class static: ", typeid(typeof(??))); } } What do I use for "??" above. John
Nov 06 2011
On 06-11-2011 14:34, J Arrizza wrote:Hi, I'm trying to get the name of the surrounding class from within a static method of the class: import std.stdio; void main(string[] args) { auto o = new SomeClass(); o.Run(); SomeClass.StaticRun(); } class SomeClass { public void Run() { writeln("In Class non-static: ", typeid(typeof(this))); } public static void StaticRun() { writeln("In Class static: ", typeid(typeof(??))); } } What do I use for "??" above. JohnConsidering the class is statically known, typeid(SomeClass)? - Alex
Nov 06 2011
On Sun, Nov 6, 2011 at 9:14 AM, Alex R=F8nne Petersen <xtzgzorex gmail.com>= wrote:Considering the class is statically known, typeid(SomeClass)? - AlexSorry, my simplified example simplified too far. I'd like to put the call into a mixin template or template, so hard-coding the class name is not an option. John
Nov 06 2011
On Sun, 06 Nov 2011 14:34:33 +0100, J Arrizza <cppgent0 gmail.com> wrote:Hi, I'm trying to get the name of the surrounding class from within a static method of the class: import std.stdio; void main(string[] args) { auto o = new SomeClass(); o.Run(); SomeClass.StaticRun(); } class SomeClass { public void Run() { writeln("In Class non-static: ", typeid(typeof(this))); } public static void StaticRun() { writeln("In Class static: ", typeid(typeof(??))); } } What do I use for "??" above.Have you tried using this? It seems to work for me: mixin template foo( ) { static void baz( ) { writeln( typeid(typeof( this ) ) ); } } class A { mixin foo!(); } void main( ) { A.baz(); // prints bar.A }
Nov 06 2011
On 11/6/11 7:34 AM, J Arrizza wrote:Hi, I'm trying to get the name of the surrounding class from within a static method of the class:typeof(this) works inside static methods too. Andrei
Nov 06 2011
On Sun, 06 Nov 2011 17:55:03 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 11/6/11 7:34 AM, J Arrizza wrote:More info: http://www.d-programming-language.org/declaration.html#typeof "typeof(this) will generate the type of what this would be in a non-static member function, even if not in a member function." -SteveHi, I'm trying to get the name of the surrounding class from within a static method of the class:typeof(this) works inside static methods too.
Nov 07 2011