constructor is not callable using argument types ()
    bearophile 
    bearophileHUGS at lycos.com
       
    Sat Dec  8 11:46:56 PST 2012
    
    
  
Suliman:
> Could you help me with this simple code. I still playing with 
> constructor, but I can't understand how to use it.
> http://www.everfall.com/paste/id.php?6n72xxxkz7ba
You have code like this:
class FileName
{
     string name;
     this(string name)
     {
         this.name = name;
     }
...
void ReadFile()
{
     auto file = new FileName();
...
As you see you define a costructor that accepts a string, but 
then when you allocate the class you don't give it a string.
So the correct code is:
void ReadFile()
{
     auto file = new FileName("somestring");
...
More notes:
- By convention in D method/function names start with a lower 
case.
- Don't indent module-level functions (like ReadFile).
- If your program is composed by more than one module, I suggest 
to add a name at the top of the imported module, like "module 
Foo;".
- In D structs are used quite often.
Bye,
bearophile
    
    
More information about the Digitalmars-d-learn
mailing list