Hi all. I'm a newbie to this forum so please forgive the odd question as first post... :-)

I'm writing myself a property class (just because I want to play with them). My property header looks something like this (all the usual clutter is removed):

#define property_readwrite( c, v, r, w ) property::property_t <c, v, &c::r, &c::w, (c::v *)0, (c::v *)0>
...
#define property( a, c, v, ... )  property_ ## a( c, v, __VA_ARGS__ )

namespace property {

template<
  typename Container,
  typename ValueType,
  ValueType (Container::*getf)(),
  void (Container::*setf)( ValueType value ),
  ValueType Container::*getv,
  ValueType Container::*setv
  >
class property_t {
  ...
  };

  ...
}

And I use the "property()" template macro thus:

class Person {
  private:
    unsigned f_age;
    void set_age( unsigned new_age );
    ...
  public:
    ...
    property( readwrite, Person, unsigned, f_age, set_age ) age;
  };

But the compiler complains that I am only supplying three of the six required template arguments. However, when I use the g++ -E option and look at my code I see:

property::property_t <Person, unsigned, (Person::unsigned *)0, &Person::set_age, &Person::f_age, (Person::unsigned *)0> age;

I've tried both the "property()" macro and the more direct "property_readwrite()" macro and both give the same error. Any idea why I am getting this grief?

Thanks in advance.

Bump.

It seems that the problem is that GCC won't let me pass NULL as a template value. There are two types of property access: direct and indirect. Direct access is when the property links directly to a class variable. Indirect is when the property links to a class method. I wanted to have the ability to use direct as well as indirect access, so my template includes fields for both types:

template<
  ...
  ValueType (Container::*getf)(),              // indirect read access
  void (Container::*setf)( ValueType value ),  // indirect write access
  ValueType Container::*getv,                  // direct read access
  ValueType Container::*setv                   // direct write access
  >

I've tried all kinds of variations, even using different types of explicit casts (static_cast, dynamic_cast, etc.) but the GCC doesn't seem to take anything except the exact type. The whole point was to include only those types applicable to the access type of property, and let the property class decide how to get/set a value based upon whether an accessor is NULL or actually points to a field or method.

I've already done all this using separate template classes for each property access type, but that septuples the number of operator overloads I have to write...

If anyone knows how to subdue GCC please help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.