Why do I get C2120 here?

MainComponent.cpp

   #include "MainComponent.h"

    //==============================================================================
    MainComponent::MainComponent()
    {
        setSize (600, 400);
        addAndMakeVisible(checkTimeButton);
        addAndMakeVisible(timeLabel);
        checkTimeButton.onClick() = [this] () {checkTimeFunction(); };
        currentTime = juce::Time::getCurrentTime();
        lastTime = currentTime;
    }

    MainComponent::~MainComponent()
    {
    }

    void MainComponent::checkTimeFunction() {
        currentTime = juce::Time::getCurrentTime();
        juce::RelativeTime timeDifference = (currentTime - lastTime);
        timeLabel.setText(juce::String(timeDifference.inMilliseconds()) + " milliseconds", juce::dontSendNotification);
        lastTime = currentTime;
    }
    //==============================================================================
    void MainComponent::paint (juce::Graphics& g)
    {
        // (Our component is opaque, so we must completely fill the background with a solid colour)
        g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));

        
    }

    void MainComponent::resized()
    {
        // This is called when the MainComponent is resized.
        // If you add any child components, this is where you should
        // update their positions.
    }

MainComponent.h

#pragma once

#include <JuceHeader.h>

//==============================================================================
/*
    This component lives inside our window, and this is where you should put all
    your controls and content.
*/
class MainComponent  : public juce::Component
{
public:
    //==============================================================================
    MainComponent();
    ~MainComponent() override;

    //==============================================================================
    void paint (juce::Graphics&) override;
    void resized() override;
    void checkTimeFunction();

private:
    //==============================================================================
    // Your private member variables go here...
    juce::TextButton checkTimeButton;
    juce::Label timeLabel;
    juce::Time currentTime = juce::Time::getCurrentTime();
    juce::Time lastTime = currentTime;
    


    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};

I didn’t add any ‘void’

onClick =

Rail

1 Like

As @railjonrogut said:

onClick =

instead of:

onClick() = 

Sometimes the bug is so obvious but it takes so much time to see it!

Sorry, but didn’t you ask the same question a few weeks ago here and got the same answer (+ a lot more detailed explanation) here: How to fix this exception? ?

8 Likes

@jacksonsteel Harassing the forums for the same issue twice is unnecessary. Not only that, it sounds like you should be reading up on C++ fundamentals!

1 Like

@jrlanglois I’m a bit surprised that you gave remonstrances to ME! :sob:

1 Like

Totally goofed that one right up! Edited.

1 Like