# Creating a custom data type for CxxWrap

**URL:** <https://discourse.julialang.org/t/creating-a-custom-data-type-for-cxxwrap/69740>\
**Category:** General Usage\
**Tags:** cxx, cxxwrap\
**Created:** [October 14, 2021, 10:46am UTC](https://discourse.julialang.org/t/creating-a-custom-data-type-for-cxxwrap/69740 "2021-10-14T10:46:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Post date:** [October 14, 2021, 10:46am UTC](https://discourse.julialang.org/t/creating-a-custom-data-type-for-cxxwrap/69740/1 "2021-10-14T10:46:24Z")

</div>

I’m trying to write a wrapper for a C++ library using CxxWrap.jl.

In C++, there are types like

```cpp
typedef struct {
  int MyType;
  int *List;
} MyRecord

typedef MyRecord *MyPointer;
typedef MyPointer *MyList;

```

To create Julia counterparts, I did

```julia
mutable struct MyRecord
  MyType::Cint
  List::Ref{Cint}
end

MyPointer = Ref{MyRecord}
MyList = Ref{MyPointer}

```

Is this how I am supposed to do? It seems not. I still get an “No appropriate factory for type” error.

---

<div class="post-metadata">

**Author:** ![jstrube](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jstrube/32/525_2.png) [@jstrube](https://discourse.julialang.org/u/jstrube)\
**Post date:** [October 14, 2021, 12:25pm UTC](https://discourse.julialang.org/t/creating-a-custom-data-type-for-cxxwrap/69740/2 "2021-10-14T12:25:39Z")

</div>

You don’t need to create the Julia classes. CxxWrap does that for you.  
Conceptually, you write the wrapper code in C++ and compile a library. Your Julia module then just imports that library; there is no other code needed on the Julia side.

The documentation is a bit dense, but there’s a fairly simple example that comes with the package. You may have to copy it out of a file with other examples, but there are fairly small examples and tests.

PS: if your struct contains custom types, you’ll need to wrap those, too

---

<div class="post-metadata">

**Author:** ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Post date:** [October 15, 2021, 4:00am UTC](https://discourse.julialang.org/t/creating-a-custom-data-type-for-cxxwrap/69740/3 "2021-10-15T04:00:15Z")

</div>

@jstrube Thanks! I managed to learn many things from the examples.
