Build Error: "Field type 'blah' is an abstract class - DragAnd Drop problem


#1

Hello all.

I am attempting to develop a midi file drag and drop location on my app, following the demo tutorial. However when I inherit the DrangAnd Drop classes:

public DragAndDropTarget,
public FileDragAndDropTarget,
public TextDragAndDropTarget

I always get the error message:

"Field type 'blah' is an abstract class"

I've made sure that the parent inherits DragAndDropContainer as per the demo, but it doesn't seem to help.

Any thoughts?

 

Thank you.


#2

I've emboldened pertinent lines of the parent for easier reading. Adding 'public DragAndDropTarget', 'public FileDragAndDropTarget', 'public TextDragAndDropTarget' to the child cpp just causes the error 'cannot instantiate abstract class'. Also, 'message' and 'somethingIsBeingDraggedOver' is coming up as undeclared, even though they are declared as a member variable in the header. Very confused. Thank you.

Parent.h


#ifndef SECTIONCONTROLS_H_INCLUDED
#define SECTIONCONTROLS_H_INCLUDED


#include "../JuceLibraryCode/JuceHeader.h"
#include "FloorComponent.h"
#include "MidiDropFile.h"


class SectionControls    : public Component,
                                        public Button::Listener,
                                        public DragAndDropContainer
{
public:
    SectionControls();
    ~SectionControls();
    void paint (Graphics& g) override;
    void resized() override;
    void buttonClicked (Button* button) override;


private:
    FloorComponent floor;
    TextButton addNewPhraseButton;
    Label addNewPhraseLabel;
    MidiDropFile midiDropFile;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SectionControls);
};
#endif
 

Parent.cpp

#include "../JuceLibraryCode/JuceHeader.h"
#include "SectionControls.h"
#include "PhraseCreator.h"


SectionControls::SectionControls()
{
    addAndMakeVisible (floor);
    
    addAndMakeVisible (addNewPhraseButton);
    addNewPhraseButton.setButtonText ("Add New Phrase");
    addNewPhraseButton.setColour(TextButton::buttonColourId, Colours::crimson);
    addNewPhraseButton.addListener(this);
    
    addAndMakeVisible (addNewPhraseLabel);
    addNewPhraseLabel.setColour (Label::backgroundColourId, Colours::black);
    addNewPhraseLabel.setColour (Label::textColourId, Colours::white);
    addNewPhraseLabel.setJustificationType (Justification::centred);
    
    addAndMakeVisible (midiDropFile);
}

SectionControls::~SectionControls()

{
    addNewPhraseButton.removeListener(this);
}

void SectionControls::paint (Graphics& g) 
{
    g.fillAll (Colours::lightblue);
}
void SectionControls::resized() 
{
    floor.setBounds (getWidth() / 10, getHeight() / 10, getWidth() + 100, 5);
    addNewPhraseButton.setBounds(5, 5, 60, 20);
    addNewPhraseButton.changeWidthToFitText();
    addNewPhraseLabel.setBounds(120, 5, 100, 20);
    midiDropFile.setBounds (5, 100, 100, 40);
}
void SectionControls::buttonClicked (Button* button)
{
    if (button == &addNewPhraseButton)
    {
        PhraseCreator newPhrase;
        newPhrase.setName("newPhrase");
        String newName = newPhrase.getName();
        addNewPhraseLabel.setText (newName, dontSendNotification);
    }
}

Child.h

#ifndef MIDIDROPFILE_H_INCLUDED
#define MIDIDROPFILE_H_INCLUDED
class MidiDropFile     :   public Component,
                                      public DragAndDropTarget,
                                      public FileDragAndDropTarget,
                                      public TextDragAndDropTarget
{                        
public:
    MidiDropFile();
    ~MidiDropFile();
    
    void paint (Graphics& g) override;
    void resized() override;
    
private:
    String message;
    bool somethingIsBeingDraggedOver;
};
#endif
 

Child.cpp

#include "../JuceLibraryCode/JuceHeader.h"
#include "MidiDropFile.h"
MidiDropFile::MidiDropFile()
                : message ("Drop Midi File Here"),
                somethingIsBeingDraggedOver (false)
{
}
MidiDropFile::~MidiDropFile()
{
}
void paint (Graphics& g)
    {
        g.fillAll (Colours::green.withAlpha (0.2f));
        // draw a red line around the comp if the user's currently dragging something over it..
        if (somethingIsBeingDraggedOver)
            {
                g.setColour (Colours::red);
                g.drawRect (getLocalBounds(), 3);
            }
        g.setColour (Colours::black);
        g.setFont (14.0f);
        g.drawFittedText (message, getLocalBounds().reduced (10, 0), Justification::centred, 4);
}
 


#3

You forgot to implement some pure virtual functions.

http://learn.juce.com/doc/classDragAndDropTarget.php

 

virtual bool DragAndDropTarget::isInterestedInDragSource  ( const SourceDetails &  dragSourceDetails )

virtual void DragAndDropTarget::itemDropped (const SourceDetails & dragSourceDetails)


#4

Thank you masshacker. For some reason adding the virtual functions didn't help the problem. However I abandoned my version, and pulled the code wholesale to my patch and it worked. Not quite sure what happened, will come back to it later when I have more experience and try and figure it out.