# Dereference a pointer in Cxx

**URL:** <https://discourse.julialang.org/t/dereference-a-pointer-in-cxx/12360>\
**Category:** General Usage\
**Tags:** cxx\
**Created:** [July 13, 2018, 9:10pm UTC](https://discourse.julialang.org/t/dereference-a-pointer-in-cxx/12360 "2018-07-13T21:10:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [July 13, 2018, 9:10pm UTC](https://discourse.julialang.org/t/dereference-a-pointer-in-cxx/12360/1 "2018-07-13T21:10:39Z")

</div>

Im trying to write an interface to a C++ library using Cxx. I’m running into a problem with pointers. Specifically, I can create a new object like so:

```
	myObj = @cxxnew Object()

```

However, I would now like to call a member function of a different class, that takes a parameter of type Object:

```
	@cxx foo->setObj(myObj)

```

This does not work, apparently because myObj is in fact a pointer to an Object:

```
  /Cxx.cpp:1:1: error: reference to type 'const Object' could not bind to an lvalue of type 'Object *'

```

So it looks like I need to dereference myObj. At least, that’s what I would do if I were writing C++ and not Julia. I cannot for the life of me find a combination of unsafe\_load() or unsafe\_pointer\_to\_objref() or any other magic incantations from the Julai C interface or Cxx library to make this work. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Ken-B](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken-b/32/1780_2.png) [@Ken-B](https://discourse.julialang.org/u/Ken-B)\
**Post date:** [September 4, 2018, 2:09pm UTC](https://discourse.julialang.org/t/dereference-a-pointer-in-cxx/12360/2 "2018-09-04T14:09:53Z")

</div>

Did you try `icxx"foo->setObj($myObj)"` ?

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [September 6, 2018, 4:17pm UTC](https://discourse.julialang.org/t/dereference-a-pointer-in-cxx/12360/3 "2018-09-06T16:17:25Z")

</div>

Yes, eventually. I was looking for a way to do is using native Julia code, and couldn’t find one. So eventually just writing C++ code directly using icxx is what worked.
