Bug 3070 – Implicitly conversion on function call

Status
RESOLVED
Resolution
INVALID
Severity
trivial
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-06-15T06:16:00Z
Last change time
2015-06-09T01:27:56Z
Assigned to
nobody
Creator
k0l0b0k.void

Comments

Comment #0 by k0l0b0k.void — 2009-06-15T06:16:02Z
I have next pieces of code: struct MyString { public MyString opAssign(string pStr) { throw new Error(""); } public MyString opCast(string pStr) { throw new Error(""); } public MyString opImplicitCast(string pStr) { throw new Error(""); } this(string pStr) { throw new Error(""); } } void foo(MyString pStr) { } int main(char[][] args) { MyString str = "test1"; str = "test2"; foo(str); foo("test3"); // error "Error: cannot implicitly convert expression ("test3") of type immutable(char)[] to MyString return 0; } This is just sample. So, my trouble is to pass string argument to foo() with implicit conversion to MyString struct (I also tried class, with no results). I'm googled by this topic, but nothing found. Can you help me? This is not a bug (I think), but the question - how I can implicitly convert from one object to another in the as C++ does (C++ will call constructor with parameter type "string"). How I can make same in D? Thanks in advance!
Comment #1 by yebblies — 2011-06-10T10:31:11Z
Not a bug, works as designed. D does not allow implicit casting like this.