Solved

Can you interpret this g++ error message?

Posted on 2002-06-23
5
205 Views
Last Modified: 2010-04-01
/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
Comment
Question by:klopter
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7101914
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
 
LVL 22

Expert Comment

by:ambience
ID: 7102703
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
 
LVL 86

Expert Comment

by:jkr
ID: 7103543
>>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
 
LVL 22

Expert Comment

by:ambience
ID: 7106730
ummm .... i think klopter must have got the point one way or the other.

klopter ????
0
 

Author Comment

by:klopter
ID: 7107952
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now