# Add type's method to Base

**URL:** <https://discourse.julialang.org/t/add-types-method-to-base/123529>\
**Category:** General Usage\
**Tags:** cxxwrap\
**Created:** [December 6, 2024, 10:06am UTC](https://discourse.julialang.org/t/add-types-method-to-base/123529 "2024-12-06T10:06:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nabla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nabla/32/26089_2.png) [@nabla](https://discourse.julialang.org/u/nabla)\
**Post date:** [December 6, 2024, 10:06am UTC](https://discourse.julialang.org/t/add-types-method-to-base/123529/1 "2024-12-06T10:06:50Z")

</div>

I want to add a method directly to Base (it’s a basic operation `:(!)`). I’m aware of  
`set_override_module(jl_base_module)` and `unset_override_module()`. However, I want to define a method for an object `myclass`, and the following does not work:

```julia
mod.add_type<myclass>
  .set_override_module(jl_base_module)
  .method("!", &myclass::operator !)
  .unset_override_module();

```

It does work without the `set_override`, but then `!` gets added to the wrong module.

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [December 6, 2024, 10:42am UTC](https://discourse.julialang.org/t/add-types-method-to-base/123529/2 "2024-12-06T10:42:28Z")

</div>

It may be easier to add a method to your module first, then add to Base from the Julia side:

```cpp
mod.add_type<myclass>
  .method(" __negate__", &myclass::operator !);

```

```julia
Base.:!(x::myclass) = __negate__ (x)

```

---

<div class="post-metadata">

**Author:** ![nabla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nabla/32/26089_2.png) [@nabla](https://discourse.julialang.org/u/nabla)\
**Post date:** [December 6, 2024, 11:18am UTC](https://discourse.julialang.org/t/add-types-method-to-base/123529/3 "2024-12-06T11:18:08Z")

</div>

That works, and I had another workaround by just installing a general method with a `[](x::myclass) { return !x; }` argument.

I tried to follow through the `Extra...` magic of cxxwrap, but could not find any way of adding an argument to `method` that would specify the module. IMO that would make sense.
