Is there a way to initialize a non-assigned structure declaration (or is it a definition)?

Too Embarrassed To Say kheaser at eapl.org
Sat Nov 10 09:40:59 PST 2012


I appreciate all the helpful replies, but I've simplified things 
to what I belive is the core issue. In C++ (at the risk of 
becoming a heretic) the language allows me to do the following:

struct SnonParameterized
{
public:
    int t;
    float u;
    SnonParameterized(int tparam, float uparam);
};

SnonParameterized::SnonParameterized(int tparam, float uparam)
{
    t = tparam;
    u = uparam;
}

SnonParameterized snp(5, 3.303);  // this compiles with Visual 
C++ 2010


===============================================================================

Now with D, I try (what I think is identical semantics) the 
following:


struct SnonParameterized
{
    int t;
    float u;
    this(int t, float u)
    {
       this.t = t
       this.u = u;
    }
}

SnonParameterized cnp(5, 3.303);  // fails compile with Error: 
found 'cnp' when expecting ';' following statement

auto hi = SnonParameterized(5, 3.303);  // compiles of course.


I'm just trying to understand why D disallows the non-assignment 
syntax.  Probably for a very good (and obvious) reason.



More information about the Digitalmars-d-learn mailing list