SNEX class instantiation, how?
-
class MyClass { public: float var1 = 0.0f; MyClass(float v1) { var1 = v1; var1(v1); // not doable, but not important if the above works } }; MyClass instance(3.14f); // Parsing error: Expected: TypeActual: $literal
-
-
I'm not entirely sure, but here is some snex that uses classes and returns no errors:
class WDFComponent { int id = 0; int type = 0; span<int, 2> links; Complex& calculateImpedance(Complex& value) { Complex n; return n; } void connect(WDFComponent comp2, int port) { links[port] = comp2.id; return; } public: auto& getFromPort(int port) { return components[links[port]]; } }; class WDFComponentCapacitor: public WDFComponent { // WDFComponentCapacitor() {} double capacitance = 0; public: void setCapacitance(double capacitance0) { capacitance = capacitance0; } public: Complex& calculateImpedance(Complex& value) { Complex denominator = multiplyComplex(value.real, value.imag, capacitance, 0.0); return reciprocalComplex(denominator); } /*capacitor.base.connect = function(WDFComponent other, int port) { connectCapacitor(capacitance, other, port); };*/ }; span<WDFComponent&, 100> components; class thing { void thing() { WDFComponent comp; auto& comp2 = comp.getFromPort(0); WDFComponentCapacitor comp3; } }; // Initialise the processing specs here void prepare(PrepareSpecs ps) { WDFComponentCapacitor cap; cap.setCapacitance(3.0); }