Solved

Can you interpret this g++ error message?

Posted on 2002-06-23
5
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

752 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