Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Can you interpret this g++ error message?

/home/kenstanley/Trilinos/packages/TSF/src/Support/TSFSmartPtr.h: In method `void
TSF::TSFSmartPtr<T>::TSFSmartPtr () [with T = TSF::TSFParameterListImplem]':
serialSolverTest.cpp:125:   instantiated from here
/home/kenstanley/Trilinos/packages/TSF/src/Support/TSFSmartPtr.h:90: invalid use of undefined type
`class TSF::TSFParameterListImplem'
/home/kenstanley/Trilinos/packages/TSF/src/Support/TSFParameterList.h:16: forward declaration of `class
TSF::TSFParameterListImplem'

The line of code that it objected to was:

TSFParameterList DirectSolverParameters ;

and here are the two relevant .h files, TSFSmartPtr.h and TSFParameterList.h:



#ifndef TSFSMARTPTR_H
#define TSFSMARTPTR_H

#include "TSFConfig.h"
#include <string>

// Solaris and IRIX CC can't handle inlines in some cases
#if defined (IRIX)
#define cond_inline
#elif defined (SOLARIS)
#define cond_inline
#else
#define cond_inline inline
#endif


namespace TSF
{
      using std::string;

      /**
       * \ingroup Utilities
       * Templated reference-counting pointer class.
       */

      template <class T>
            class TSFSmartPtr {
            public:
            cond_inline TSFSmartPtr(T* ptr = 0);
            cond_inline TSFSmartPtr(const TSFSmartPtr<T>& other);
            cond_inline TSFSmartPtr(T* ptr, int* refCount);
            ~TSFSmartPtr();
            const TSFSmartPtr<T>& operator =(const TSFSmartPtr<T>& rhs);
            cond_inline T* operator ->();
            cond_inline bool isNull() const;
            cond_inline const T* operator ->() const;
            /** Read/write dereferencing */
            cond_inline T& operator *();
            /** Read-only dereferencing */
            cond_inline const T& operator *() const;
            cond_inline operator const T* () const;
            cond_inline bool isNonUnique() const;

            cond_inline int refCount() const;

            cond_inline void error(const string& msg) const ;

            protected:
            T* ptr_;
            int* refCount_;
      };

      void smartPtrError(const string& msg);

      template <class T> cond_inline
            TSFSmartPtr<T>::TSFSmartPtr(T* ptr)
            : ptr_(ptr),
            refCount_(0)
            {
                  if (ptr_) {
                        refCount_ = new int;
                        if (refCount_ == 0)
                              error("TSFSmartPtr::TSFSmartPtr(T* ptr) out of memory");
                        *refCount_ = 1;
                  }
            }

      template <class T> cond_inline
            TSFSmartPtr<T>::TSFSmartPtr(T* ptr, int* refCount)
            : ptr_(ptr),
            refCount_(refCount)
            {
                  *refCount++;
            }

      template <class T> cond_inline
            TSFSmartPtr<T>::TSFSmartPtr(const TSFSmartPtr<T>& other)
            : ptr_(other.ptr_),
            refCount_(other.refCount_)
            {
                  if (refCount_ != 0)
                        ++(*refCount_);
            }

      template <class T>
            TSFSmartPtr<T>::~TSFSmartPtr()
            {
                  if (refCount_ != 0 && --(*refCount_) == 0)
                        {
                              delete ptr_;
                              ptr_ = 0;
                              delete refCount_;
                              refCount_ = 0;
                        }
            }

      template <class T>
            const TSFSmartPtr<T>& TSFSmartPtr<T>::operator =(const TSFSmartPtr<T>& rhs)
      {
            if (ptr_ != rhs.ptr_)
                  {
                        if (refCount_ != 0 && --(*refCount_) == 0)
                              {
                                    delete ptr_;
                                    delete refCount_;
                              }
                        ptr_ = rhs.ptr_;
                        refCount_ = rhs.refCount_;
                        if (refCount_ != 0)
                              ++(*refCount_);
                  }
            return *this;
      }

      template <class T> cond_inline
            bool TSFSmartPtr<T>::isNull() const {
            return (ptr_ == 0);
      }

      template <class T> cond_inline
            T* TSFSmartPtr<T>::operator ->() {

            if (ptr_ == 0)
                  error("TSFSmartPtr<T>::operator ->() on null pointer");
            return ptr_;
      }

      template <class T> cond_inline
            const T* TSFSmartPtr<T>::operator ->() const {
            if (ptr_ == 0)
                  error("TSFSmartPtr<T>::operator ->() on null pointer");
            return ptr_;
      }

      template <class T> cond_inline
            T& TSFSmartPtr<T>::operator *() {
            if (ptr_ == 0)
                  error("TSFSmartPtr<T>::operator *() on null pointer");
            return *ptr_;
      }

      template <class T> cond_inline
            const T& TSFSmartPtr<T>::operator *() const {
            if (ptr_ == 0)
                  error("TSFSmartPtr<T>::operator *() on null pointer");
            return *ptr_;
      }

      template <class T> cond_inline
            TSFSmartPtr<T>::operator const T* () const {
            return ptr_;
      }

      template <class T> cond_inline
            bool TSFSmartPtr<T>::isNonUnique() const {
            return refCount_ == 0 ? false : *refCount_ != 1;
      }

      template <class T> cond_inline
            int TSFSmartPtr<T>::refCount() const {
            return refCount_ == 0 ? 0 : *refCount_;
      }
      
      template <class T>
            void TSFSmartPtr<T>::error(const string& msg) const
            {
                  smartPtrError(msg);
            }
}

#undef cond_inline
#endif











#ifndef TSFPARAMETERLIST_H
#define TSFPARAMETERLIST_H

#include "TSFConfig.h"
#include "TSFSmartPtr.h"
#include "TSFParameter.h"
#include <string>
#include "TSFArray.h"

namespace TSF
{

      using namespace std;

      /** forward declare class TSFParameterListImplem */
      class TSFParameterListImplem;

      /** \ingroup Utilities
       *
       */
      class TSFParameterList
            {
            public:
                  /** empty ctor, for use in containers */
                  TSFParameterList();

                  /** construct with a descriptive label */
                  TSFParameterList(const string& label);
                  
                  /** return descriptive label */
                  const string& getLabel() const ;

                  /** make a deep copy */
                  TSFParameterList deepCopy() const ;

                  //@{ \name Child lists
                  /** Add a new child list. The child's name is expected to be unique. */
                  void addChild(const TSFParameterList& list);

                  /** Look up a child list by name */
                  TSFParameterList getChild(const string& name) const ;

                  /** get list of all children */
                  TSFArray<TSFParameterList> listChildren() const ;
                  //@}


                  //@{ \name Creating parameters

                  /** Add a new parameter to the list. The parameter's name is checked against
                   * the list of existing names to ensure that each name appears only once.
                   * If the parameter's name already appears, an error is thrown. To change the
                   * value of an existing parameter, use the setValue() method instead. */
                  void addParameter(const TSFParameter& parameter);
                  
                  //@}


                  //@{ \name Setting parameter values

                  /** set the value of an existing character parameter.  The
                   * parameter's name is expected to be in the list; if not, an
                   * error is thrown. To add a new parameter to the list, use the
                   * add() method instead. */
                  void setValue(const string& name, char value);

                  /** set the value of an existing string parameter.  The
                   * parameter's name is expected to be in the list; if not, an
                   * error is thrown. To add a new parameter to the list, use the
                   * add() method instead. */
                  void setValue(const string& name, const string& value);

                  /** set the value of an existing integer parameter.  The
                   * parameter's name is expected to be in the list; if not, an
                   * error is thrown. To add a new parameter to the list, use the
                   * add() method instead. */
                  void setValue(const string& name, int value);


                  /** set the value of an existing double parameter.  The
                   * parameter's name is expected to be in the list; if not, an
                   * error is thrown. To add a new parameter to the list, use the
                   * add() method instead. */
                  void setValue(const string& name, double value);

                        /** set the value of an existing int array parameter.  The
                   * parameter's name is expected to be in the list; if not, an
                   * error is thrown. To add a new parameter to the list, use the
                   * add() method instead. */
                  void setValue(const string& name, const TSFArray<int>& value);

                  /** set the value of an existing double parameter.  The
                   * parameter's name is expected to be in the list; if not, an
                   * error is thrown. To add a new parameter to the list, use the
                   * add() method instead. */
                  void setValue(const string& name, const TSFArray<double>& value);

                  //@}
                  
                  //@{ \name Getting parameters
                  /** Look up a parameter by name */
                  TSFParameter getParameter(const string& name) const ;

                  /** Return a list of all parameters */
                  TSFArray<TSFParameter> listParameters() const ;
                  //@}

                  //@{ \name Getting information about labels
                  /** Return a list of all parameter names */
                  TSFArray<string> listParameterNames() const ;

                  /** Return a list of all child names */
                  TSFArray<string> listChildNames() const ;
                  //@}

                  /** write to a string */
                  string toString() const ;
                  
            private:
                  TSFSmartPtr<TSFParameterListImplem> ptr_;
            };

      /** \relates TSFParameterList */
      string toString(const TSFParameterList& p) {return p.toString();}
}

#endif


0
klopter
Asked:
klopter
  • 2
  • 2
1 Solution
 
jkrCommented:
It seems that you have a foward declaration of "TSF::TSFParameterListImplem", but are using an instance instead of a pointer. Can you just include the header file that holds the declatration of "TSF::TSFParameterListImplem" instead of foward declaring it?
0
 
ambienceCommented:
jkr, he is not using an instance , the problem is with the template definition and that too is because of the fact that all the function defnitions for templates must reside in the header file.

The TSFSmartPtr template member functions need information about the parameter class, and that is why you ought to include the header for TSFParameterListImplem before you can do something like

TSFSmartPtr<TSFParameterListImplem>

If only you can split the TSFSmartPtr header like you do with an ordinary C++ class, i suspect there wont be any such problems, but this is not possible with atleast the compilers that i know.

correct me if wrong ..
0
 
jkrCommented:
>>he is not using an instance

By using an auto pointer, he 'sort of' is, as it reads

TSFSmartPtr<TSFParameterListImplem> ptr_;

and not

TSFSmartPtr<TSFParameterListImplem*> ptr_;

0
 
ambienceCommented:
ummm .... i think klopter must have got the point one way or the other.

klopter ????
0
 
klopterAuthor Commented:
Please accept my apologies for the delay in responding.  I got distracted by other responsibilities.

ambience - thanks for your comments as well.  If I could split my points, I would.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now