DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005
    Posts
    13

    inheritance help

    I need to call a function declared like this:
    Code:
    bool addParameterEntry(const string& name, ObjectType& object,
    ValueType ObjectType::* object_val_ptr);
    and also overloaded like this:
    Code:
    template <class FunctorType, class ValueType>
    bool addParameterEntry(const string& name, FunctorType* fctr);
    I have been calling it like this:
    Code:
    paramLib.addParameterEntry("Q", problem, &ExpWaveProb::Q);
    where ExpWaveProb looks like:
    Code:
    class ExpWaveProb : public WaveProb
    {
    public:
      double Q;
    //...
    }
    But now that I have made Q a member of WaveProb (and thus ExpWaveProb inherits it), the call above generates the error:

    no matching function for call to `LOCA::Parameter::Library::addParameterEntry(const char[2], ExpWaveProb&, double WaveProb::*)'

    What would be the easiest way to fix this without changing the addParameterEntry method?

    Thanks,
    Josh

    P.S. Why the functor syntax for a nonstatic field such as Q? I'd have thought to pass it something like &myExpWaveProbReference.Q instead of &ExpWaveProb::Q, so I'm confused.
    Last edited by jab630; 09-02-2005 at 12:40 AM.

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    First of, you can't use quoted literals as template arguments. I won't bore you with the technical explanation why this is illegal but remember that templae type matching rules are very strict, unlike say function overloading resolution. Instead of passing "Q" as the first argument, pass <const string("Q"), ...>
    As for the syntax: the :: operator differs from the . operator in one crucial aspect: the former applies to type names (i.e., classes) and namespaces. The latter must take an object instance as the lefthand argument. A pointer to a member function is something that belongs to a class, not an object (you can't define a member function in one object). Of course, when calling that member you call it for a specific instance but the member function's address is fixed and shared by all objects of the same class.
    Danny Kalev

Similar Threads

  1. inheritance
    By pranks in forum ASP.NET
    Replies: 2
    Last Post: 04-16-2002, 08:29 PM
  2. Visual Inheritance - Very Temperamental
    By Steve Hall in forum .NET
    Replies: 4
    Last Post: 04-04-2002, 09:15 AM
  3. is inheritance useless?
    By Patrick Troughton in forum .NET
    Replies: 158
    Last Post: 03-05-2002, 08:29 AM
  4. Replies: 3
    Last Post: 09-11-2001, 05:06 AM
  5. Inheritance of Class with Private Memebers?
    By David Reeves in forum Java
    Replies: 5
    Last Post: 10-24-2000, 10:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links