HISE Logo Forum
    • Categories
    • Register
    • Login

    SNEX class instantiation, how?

    Scheduled Pinned Locked Moved Unsolved C++ Development
    2 Posts 2 Posters 120 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ustkU
      ustk
      last edited by

      @Christoph-Hart

      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
      

      Can't help pressing F5 in the forum...

      griffinboyG 1 Reply Last reply Reply Quote 0
      • ustkU ustk marked this topic as a question on
      • griffinboyG
        griffinboy @ustk
        last edited by griffinboy

        @ustk

        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);	
        	}
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post

        27

        Online

        1.7k

        Users

        11.8k

        Topics

        102.8k

        Posts