[cable] How do you wrap implicitly defined operator=() ?

Steven Levitt slevitt at siac.com
Tue Dec 24 16:36:57 EST 2002


I've finally gotten Cable and GCCXML to build and run on HP-UX 11 using GCC
3.2. Now the fun starts...:)

If I have a  C++ class whose assignment operator (operator=()) is
implicitly defined, is there any way to get Cable to generate a wrapper for
this operator?

For example, suppose I define a class like the following:

namespace FooTest
{
     class Foo
     {
     public:
          Foo() : m_x(0) { }
          explicit Foo(int x) : m_x(x) { }

          //Default copy ctor and op=()

          int getX() const { return m_x ; }

     private:
          int m_x ;
     } ;
}

and I define a cable config file thus:

#include "Foo.h"

#ifdef CABLE_CONFIGURATION
namespace _cable_
{
    const char* const group="FooTest1";
    const char* const package="FooTest";
    const char* const groups[]={"FooTest1"};

     namespace wrappers
     {
          typedef FooTest::Foo Foo ;
     }
}
#endif

Now, I try to assign the value of one instance of Foo to another instance
in Tcl:

% set foo [Foo 1]
_cxx40027ef8
% $foo = [Foo 2]
No method matches FooTest::Foo::=(FooTest::Foo)

So, apparently, Cable hasn't generated a wrapper for the assignment
operator.  I can confirm this by calling "cable::ListMethods $foo."

However, if I define another class, Foo2, with an explicit assignment
operator, I can call that:

namespace FooTest
{
     class Foo2
     {
     public:
          Foo2() : m_x(0) { }
          explicit Foo2(int x) : m_x(x) { }

          //Default copy ctor, but explicit op=

          Foo2& operator=(const Foo2& other) { m_x = other.m_x ; return
*this ; }

          int getX() const { return m_x ; }

     private:
          int m_x ;
     } ;
}

% set foo2 [Foo2 1]
_cxx40027fb8
% $foo2 = [Foo2 2]
_cxx4000c690
% $foo2 getX
2



More information about the cable mailing list