How to properly create a derived class from this v8 class

LeonMrBonnie

So I have a class that is in v8 that I want my own class to derive from and then instantiate an instance of my own class.

In v8 there is the class with this signature:

class V8_EXPORT CodeEventHandler {
 public:
  /**
   * Creates a new listener for the |isolate|. The isolate must be initialized.
   * The listener object must be disposed after use by calling |Dispose| method.
   * Multiple listeners can be created for the same isolate.
   */
  explicit CodeEventHandler(Isolate* isolate);
  virtual ~CodeEventHandler();

  /**
   * Handle is called every time a code object is created or moved. Information
   * about each code event will be available through the `code_event`
   * parameter.
   *
   * When the CodeEventType is kRelocationType, the code for this CodeEvent has
   * moved from `GetPreviousCodeStartAddress()` to `GetCodeStartAddress()`.
   */
  virtual void Handle(CodeEvent* code_event) = 0;

  /**
   * Call `Enable()` to starts listening to code creation and code relocation
   * events. These events will be handled by `Handle()`.
   */
  void Enable();

  /**
   * Call `Disable()` to stop listening to code creation and code relocation
   * events.
   */
  void Disable();

 private:
  CodeEventHandler();
  CodeEventHandler(const CodeEventHandler&);
  CodeEventHandler& operator=(const CodeEventHandler&);
  void* internal_listener_;
};

And my own derived class looks like this:

class CodeEventHandler : public v8::CodeEventHandler
{
public:
    ~CodeEventHandler()
    {
        listeners.clear();
    }

    void Handle(v8::CodeEvent* event)
    {
        // code omitted for readibility
    }

    v8::Local<v8::Object> SerializeEvent(v8::CodeEvent* event)
    {
        // code omitted for readibility
    }

    void AddListener(v8::Local<v8::Function> listener)
    {
        // code omitted for readibility
    }

    void SetResource(CV8ResourceImpl* _resource)
    {
        resource = _resource;
    }

private:
    CV8ResourceImpl* resource;
    std::vector<v8::UniquePersistent<v8::Function>> listeners;
};

But when I want to instantiate my class like this:

v8::Isolate* isolate = v8::Isolate::GetCurrent();
auto codeEventHandler = new CodeEventHandler(isolate);

I get this error:

error C2664: 'CodeEventHandler::CodeEventHandler(const CodeEventHandler &)': cannot convert argument 1 from 'v8::Isolate *' to 'const CodeEventHandler &'

What am I doing wrong?

jmrk

(This is not a V8-specific question; it's plain C++.)

As @JosephLarson points out, you need a constructor with the right signature. Add this to your class:

explicit CodeEventHandler(Isolate* isolate)
    : v8::CodeEventHandler(isolate) {
  // any code you need to initialize your subclass instances...
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to properly combine functions from based and derived class to avoid warnings?

From Dev

Create a base class object from a derived class

From Dev

Create an instance of derived class from the base class

From Dev

How to Create an Instance of a Class in runtime derived from ObservableCollection<T>?

From Dev

How to create abstract class until Derived Instantiation

From Dev

how to create a derived pointer class variable?

From Dev

How can I create an instance of a derived class from an instance of a base class and include private fields?

From Dev

How to properly create a class to hold data from JSON with Alamofire and SwiftyJSON

From Dev

How to create object of nameless derived class of my abstract class?

From Dev

How to create an object of a derived class in a base class in c++

From Dev

Derive a class from a derived class

From Dev

How to draw text in derived from QHeaderView class

From Dev

How Get data from a derived class?

From Dev

Qt - how to emit a signal from derived class?

From Dev

How to implement a derived class and call it from a Button?

From Dev

How to call an operator from a base class within the derived class?

From Dev

How to access Interface method implemented in the derived class from child class?

From Java

How to call a parent class function from derived class function?

From Dev

How to call a function from a derived class in a base class?

From Dev

How to Get Base Class Instance from a Derived Class

From Dev

How to call derived class method from base class pointer?

From Dev

How to use a covariant return to retrieve a derived class from a base class?

From Dev

how to access derived class object from abstract class in boost python

From Dev

How do I access an inner class constructor from a derived class?

From Dev

How to get only base class properties from derived class?

From Dev

Create a derived class from a boost-python wrapped factory

From Dev

How to forbid C++ derived class to derive from base, but allow from another derived class

From Dev

How to call derived class virtual method from another derived class object

From Dev

hiding property from derived class

Related Related

  1. 1

    How to properly combine functions from based and derived class to avoid warnings?

  2. 2

    Create a base class object from a derived class

  3. 3

    Create an instance of derived class from the base class

  4. 4

    How to Create an Instance of a Class in runtime derived from ObservableCollection<T>?

  5. 5

    How to create abstract class until Derived Instantiation

  6. 6

    how to create a derived pointer class variable?

  7. 7

    How can I create an instance of a derived class from an instance of a base class and include private fields?

  8. 8

    How to properly create a class to hold data from JSON with Alamofire and SwiftyJSON

  9. 9

    How to create object of nameless derived class of my abstract class?

  10. 10

    How to create an object of a derived class in a base class in c++

  11. 11

    Derive a class from a derived class

  12. 12

    How to draw text in derived from QHeaderView class

  13. 13

    How Get data from a derived class?

  14. 14

    Qt - how to emit a signal from derived class?

  15. 15

    How to implement a derived class and call it from a Button?

  16. 16

    How to call an operator from a base class within the derived class?

  17. 17

    How to access Interface method implemented in the derived class from child class?

  18. 18

    How to call a parent class function from derived class function?

  19. 19

    How to call a function from a derived class in a base class?

  20. 20

    How to Get Base Class Instance from a Derived Class

  21. 21

    How to call derived class method from base class pointer?

  22. 22

    How to use a covariant return to retrieve a derived class from a base class?

  23. 23

    how to access derived class object from abstract class in boost python

  24. 24

    How do I access an inner class constructor from a derived class?

  25. 25

    How to get only base class properties from derived class?

  26. 26

    Create a derived class from a boost-python wrapped factory

  27. 27

    How to forbid C++ derived class to derive from base, but allow from another derived class

  28. 28

    How to call derived class virtual method from another derived class object

  29. 29

    hiding property from derived class

HotTag

Archive