No main() Error

Ron Tarrant rontarrant at gmail.com
Sat Feb 15 13:05:54 UTC 2025


On Wednesday, 12 February 2025 at 18:57:28 UTC, Walter Bright 
wrote:
> I'm not sure what code you're writing. Can you post an example, 
> please?

Hi, Walter. Thanks for replying.

Although the errors may not be the same (I don't remember what 
errors I got, frankly. I've put the entire experience out of my 
mind since it was a tad embarrassing and I've long since tossed 
the code.) it was something like this:

```
module copy_file_std;

import std.stdio;
import std.file;
import std.exception;

// this is a new comment
void copyFile(string sourcePath, string destinationPath)
{
	try
	{
		// Option 1: Using std.file.copy (Simplest for basic copies)
		copy(sourcePath, destinationPath);
		writeln("File copied successfully using std.file.copy.");
	}
	catch (Exception e)
	{
		stderr.writeln("Error copying file: ", e.msg);
	}
}

string source = "./copy_file_std.d";
string destination = "./subdir/copy_file_std.d";

if (!exists(source))
{
	stderr.writeln("Source file does not exist!");
	return;
}

copyFile(source, destination);
```


I neglected to wrap the last statement in ```void main() {}``` 
which, naturally, fixed it.


More information about the dip.ideas mailing list