www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Error: class myClass.myClass() is used as a type

reply "rsk82" <rsk82 live.com> writes:
this is my module:

module myClass;

class myClass () {
   this() {

   }
};

and main app:

import myClass;

int main() {
   myClass my_instance = new myClass();
   return 0;
}

What's wrong here ?
Jan 27 2013
next sibling parent "Dicebot" <m.strashun gmail.com> writes:
On Sunday, 27 January 2013 at 19:55:07 UTC, rsk82 wrote:
 this is my module:

 module myClass;

 class myClass () {
   this() {

   }
 };

 and main app:

 import myClass;

 int main() {
   myClass my_instance = new myClass();
   return 0;
 }

 What's wrong here ?

new MyClass.MyClass(), I suppose. Despite import is public, module symbol has higher priority in name resolution.
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 20:04:17 UTC, Dicebot wrote:
 new MyClass.MyClass(), I suppose. Despite import is public, 
 module symbol has higher priority in name resolution.

Nope. I changed module name to myClass_mod, now got this: Error: class myClass_mod.myClass() is used as a type
Jan 27 2013
prev sibling next sibling parent reply "Daniel Kozak" <kozzi11 gmail.com> writes:
On Sunday, 27 January 2013 at 19:55:07 UTC, rsk82 wrote:
 this is my module:

 module myClass;

 class myClass () {
   this() {

   }
 };

 and main app:

 import myClass;

 int main() {
   myClass my_instance = new myClass();
   return 0;
 }

 What's wrong here ?

class myClass () { this() { } }; should be class myClass { this() { } }
Jan 27 2013
next sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/27/13 3:29 PM, jerro wrote:
 You need to put myClass_mod.d (or what ever the file name is) on the
 command line. You could also use rdmd, which will find all the imported
 files automatically.

BTW I just sent a pull request that makes rdmd faster for large projects by reducing the number of stat calls: https://github.com/D-Programming-Language/tools/pull/41 Andrei
Jan 27 2013
prev sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 01/27/2013 12:13 PM, Daniel Kozak wrote:
 On Sunday, 27 January 2013 at 19:55:07 UTC, rsk82 wrote:

 What's wrong here ?

class myClass () { this() { } }; should be class myClass { this() { } }

Yeah... Those empty parentheses were making myClass a class template, not a class. Apparently the syntax (or the compiler) allows template definitions without template parameters, which can still be instantiated: class myClass () { this() { } } int main() { myClass!() my_instance = new myClass!(); return 0; } Ali
Jan 27 2013
prev sibling next sibling parent "Namespace" <rswhite4 googlemail.com> writes:
All of your topics shouldn't be here. Post in D.learn instead.
Jan 27 2013
prev sibling next sibling parent "rsk82" <rsk82 live.com> writes:
On Sunday, 27 January 2013 at 20:13:05 UTC, Daniel Kozak wrote:
 should be

 class myClass {
    this() {

    }
 }

Thanks, that killed the original error. Now the linker says: OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html t3.obj(t3) Error 42: Symbol Undefined _D11myClass_mod7myClass6__ctorMFZC11myClass_mod7myClass t3.obj(t3) Error 42: Symbol Undefined _D11myClass_mod7myClass7__ClassZ --- errorlevel 2 Namespace: ok, I will post my new topics there, but I like to end with this issue and not create another topic for that.
Jan 27 2013
prev sibling next sibling parent "jerro" <a a.com> writes:
On Sunday, 27 January 2013 at 20:24:38 UTC, rsk82 wrote:
 On Sunday, 27 January 2013 at 20:13:05 UTC, Daniel Kozak wrote:
 should be

 class myClass {
   this() {

   }
 }

Thanks, that killed the original error. Now the linker says: OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html t3.obj(t3) Error 42: Symbol Undefined _D11myClass_mod7myClass6__ctorMFZC11myClass_mod7myClass t3.obj(t3) Error 42: Symbol Undefined _D11myClass_mod7myClass7__ClassZ --- errorlevel 2 Namespace: ok, I will post my new topics there, but I like to end with this issue and not create another topic for that.

You need to put myClass_mod.d (or what ever the file name is) on the command line. You could also use rdmd, which will find all the imported files automatically.
Jan 27 2013
prev sibling next sibling parent "F i L" <witte2008 gmail.com> writes:
rsk82 wrote:
 What's wrong here ?

module myClass (myclass.d); class myClass() { this() { ... } } and main app (main.d): import myclass; void main() { myClass my_instance = new myClass(); } then compile with: $ dmd main.d myclass.d or: $ dmd main myclass or: $ rdmd main ps. Module names should be lowercase (see docs), and you can safely use 'void' for main()
Jan 28 2013
prev sibling parent "F i L" <witte2008 gmail.com> writes:
F i L wrote:
     class myClass() {
         this() { ... }
     }

Whoops, forgot to remove the '()' after 'myClass'. As others have pointed out, that will make 'myClass' a template-class.
Jan 28 2013