Initializing a class pointer

Tyro[a.c.edwards] nospam at home.com
Sat Feb 26 14:56:58 PST 2011


class Class{}

void main()
{
Class myClass;
Class* pClass0 = &myClass;  // OK

Class* pClass1 = new Class; // Error: cannot implicitly convert     [8]
                             // expression (new Class) of type t.Class
                             // to test.Class*
	
Class* pClass2 = &(new Class);
                             // Error: new Class is not an lvalue    [12]
	
Class mClass = &(new Class);// Error: cannot implicitly convert     [14]
	                    // expression (&new Class) of type Class*
	                    // to test.Class
}

C++ uses the process on line [8] above to initialize a class pointer. 
Obviously it does not work in D. But given the error message at [14], I 
thought [12] would have been allowed. What is the proper way to convert 
[8] to D?

Thanks


More information about the Digitalmars-d-learn mailing list