How to use classes from another d files

Vinod K Chandran kcvinu82 at gmail.com
Tue Oct 22 17:34:51 UTC 2019


Hi all,
I am new to D. But some fair experience with vb.net. I was 
playing with D classes.  I wrote a class in a D file.
The file name is "classFile.d"
```D
class TestClass {

     int myIntVar        ;
     string myStringVar  ;

     this(int miv, string msv) {
         this.myIntVar = miv     ;
         this.myStringVar = msv  ;
     }//End this

}//End Class
```
And i wrote my main function in another file named "caller.d". 
Both these files are in same folder.
```D
import std.stdio ;

void main() {
     import classFile ;


     TestClass tc = new TestClass(37, "Sample String") ;
     writeln(tc.myStringVar) ;
     tc.myIntVar = 45 ;
     writeln(tc.myIntVar)  ;

     writeln("its over..") ;

}//End main
```
This is the error message i got.
;------------------------------------------------
caller.obj(caller)
  Error 42: Symbol Undefined 
__D9classFile9TestClass6__ctorMFiAyaZCQBjQBc
caller.obj(caller)
  Error 42: Symbol Undefined __D9classFile9TestClass7__ClassZ
Error: linker exited with status 2
PS E:\OneDrive Folder\OneDrive\Programming\D 
Programming\Samples\Sample2>





More information about the Digitalmars-d-learn mailing list