Yes sorry, that was exactly my problem, my example code is not exaustive.
I have the char* in a gobject structure like this:

struct _GMdsSignal
{
  GMdsObject parent;
  gchar *name;
  GMdsExperiment *experiment;
  gint length;
...

-------[this method makes the object instance in c]------
GMdsObject *g_mds_signal_new(const gchar *name);



---[ than a header wrap that structure in a C++ object: ]------

class GMds_Signal : public GMds_Object
{
public:
  GMds_Signal(const char * name) : GMds_Object()
  { obj_ = g_mds_signal_new( (gchar *)strdup(name) ); }
....
in the last line obj_ is a pointer of GMdsObject type 

strdup makes a copy of the string for the c structure...


is this the best way to do it?


Thankyou very much Xavier,


Andrea


2010/8/31 Xavier Delacour <xavier.delacour@gmail.com>
Perhaps I am misunderstanding the question. Is the problem just that
you're not making a copy of the string? eg, fix with [1]

Xavier

[1]
%inline %{
#include <stdio.h>
#include <string>

class Test{
private:
 std::string test_string;
public:
 Test (const char *p)
 { test_string = p; }
 void print_string()
 { printf("%s\n",test_string.c_str()); }
};
%}

On Tue, Aug 31, 2010 at 5:15 AM, Andrea <andrea@bluesteam.it> wrote:
> Hi, I'm new to swig programming, sorry to bother with probably obvius
> question..
>  I can't find correct documentation to handle this simple case in octave
> wrapper:
> ---------------[test.i]-------------
> %module test
> %inline %{
> #include <stdio.h>
> class Test{
> private:
>   char *test_string;
> public:
>   Test (char *p)
>   { test_string = p; }
>   void print_string()
>   { printf("%s\n",test_string); }
> };
> %}
> --------[ compiled with: ]------------
> swig-1.3 -octave -c++ -o test_wrap.cc test.i
> mkoctfile3.2 -o test.oct test_wrap.cc
>
> ----------[octave:]----------------
> octave:1> test
> octave:2> p = Test("foo")
> {
>   Test, ptr = 0x8f22338
>   print_string (method)
> }
> octave:3> p.print_string()
> ���
>
> If I set variable to public I can use the wrapper accessor function.
> How can I handle it with my own constructor?
> Thanks in advance,
> Andrea
> ------------------------------------------------------------------------------
> This SF.net Dev2Dev email is sponsored by:
>
> Show off your parallel programming skills.
> Enter the Intel(R) Threading Challenge 2010.
> http://p.sf.net/sfu/intel-thread-sfd
> _______________________________________________
> Swig-user mailing list
> Swig-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/swig-user
>
>