Re: Unable to match function definition to an existing declaration

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 11/17/04

  • Next message: Doug Harrison [MVP]: "Re: Unable to match function definition to an existing declaration"
    Date: Wed, 17 Nov 2004 15:07:40 -0500
    
    

    Murrgon wrote:
    > Consider the following for VC7.1
    >
    > //
    > ===========================================================================
    > #include <vector>
    > using namespace std;
    >
    > template <class TYPE>
    > class TArray : public vector<TYPE>
    > {
    > public:

    Add here:

          typedef typename vector<TYPE>::size_type size_type;

    > inline size_type GetAllocSize() const;
    > };
    >
    > template<class TYPE>
    > inline typename vector<TYPE>::size_type TArray<TYPE>::GetAllocSize() const

    Change to

    inline
       typename TArray<TYPE>::size_type
                  TArray<TYPE>::GetAllocSize() const

    > {
    > return(vector<TYPE>::capacity());
    > }
    >
    >
    > //
    > ===========================================================================
    > // Main
    > ======================================================================
    > //
    > ===========================================================================
    > int main()
    > {
    > TArray<int> aIntegers;
    > return 0;
    > }
    >
    > //
    > ===========================================================================
    >
    > This gives me a C2244 error: "unable to match function definition to an
    > existing declaration". The help on error C2244 says "An unusual use of
    > the unary + operator was used in front of a function call that did not have
    > parenthesis."
    >
    > What?
    >
    > I don't see any + operator in use here. Can someone tell me what is
    > actually
    > wrong here?

    It can't find 'size_type' when processing the declaration. There must be
    some weirdness in the way dependent types are resolved in VC++, but I am
    too lazy now to track them down. This:
    ---------------------------------------------
    #include <vector>
    using namespace std;

    template <class TYPE>
    class TArray : public vector<TYPE>
    {
    public:
       typename vector<TYPE>::size_type GetAllocSize() const;
    };

    template<class TYPE>
    inline typename vector<TYPE>::size_type TArray<TYPE>::GetAllocSize() const
    {
       return vector<TYPE>::capacity();
    }

    int main()
    {
       TArray<int> aIntegers;
    }
    ---------------------------------------------
    doesn't compile (although it should). It can't find that "vector<TYPE>"
    is the actual base class of 'TArray<TYPE>'.

    I checked with VC++ v8, and it can't compile it either. I am not going
    to submit a bug report for that, too lazy. Besides, it probably has
    already been reported.

    V


  • Next message: Doug Harrison [MVP]: "Re: Unable to match function definition to an existing declaration"

    Relevant Pages

    • Nested Union Structure and scope resolution operator
      ... using namespace std; //introduces namespace std ... I tried to compile the source using both C++ Builder and Metrowerks ...
      (alt.comp.lang.learn.c-cpp)
    • Re: STL on Solaris system
      ... I would like compile a little program in c++ ... using namespace std; ... test.cpp: In function 'int main': ... This is free software; see the source for copying conditions. ...
      (comp.unix.solaris)
    • Re: collect2: ld returned 8 exit status
      ... I'm trying to compile a short piece of code in C++: ... using namespace std; ... int main ... $ g++ test.cpp -o testcpp ...
      (comp.unix.aix)
    • Re: C++ compile error
      ... > hello.C: In function `int main': ... +using namespace std; ... > complex language when I compile my first program. ... > This post may off topic of FreeBSD, ...
      (freebsd-questions)
    • Re: std::vector<> error.
      ... gives me an compile error. ... int main ... When i compile the above file using ... I'd suggest that you file a bug report. ...
      (comp.unix.solaris)