CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Template/typename problem.......one for the gurus!

  1. #1
    Join Date
    Dec 2006
    Posts
    18

    Template/typename problem.......one for the gurus!

    Hi, the following code segment is found in a file called stl_alloc.h:



    template <bool __threads, int __inst>
    typename __default_alloc_template<__threads, __inst>::_Obj* __STL_VOLATILE //line 572
    __default_alloc_template<__threads, __inst> ::_S_free_list[
    # if defined(__SUNPRO_CC) || defined(__GNUC__) || defined(__HP_aCC)
    _NFREELISTS
    # else
    __default_alloc_template<__threads, __inst>::_NFREELISTS
    # endif
    ] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };



    And when I build it it causes the following errors:

    >.\stl\stl_alloc.h(572) : warning C4346: 'std::__default_alloc_template<threads,inst>::_Obj' : dependent name is not a type

    1> prefix with 'typename' to indicate a type

    1>.\stl\stl_alloc.h(572) : error C2143: syntax error : missing ';' before '*'

    1>.\stl\stl_alloc.h(572) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    1>.\stl\stl_alloc.h(572) : error C2888: '__default_alloc_template<threads,inst>::_Obj _Obj' : symbol cannot be defined within namespace 'std'

    1>.\stl\stl_alloc.h(572) : fatal error C1903: unable to recover from previous error(s); stopping compilation





    This code used to run on a PPC2003 device and was compiled using eVC4. I am now trying to build it using VS2005. But now I believe that because:

    The typename keyword is required if a dependent name is to be treated as a type. This is a breaking change in the Visual C++ .NET 2003 compiler, made in order to conform to the ISO C++ standard.



    This problem has to do with templates and typenames. Does anyone know how I must modify the above code in order to build.



    I really appreciate any help i can get on this one.



    Thanks



    Harry

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Template/typename problem.......one for the gurus!

    Quote Originally Posted by Harry123
    Hi, the following code segment is found in a file called stl_alloc.h:
    Please show us your code. We can't fix what we can't see.
    This problem has to do with templates and typenames. Does anyone know how I must modify the above code in order to build.
    Modify the library code, and not your own code???

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Dec 2006
    Posts
    18

    Re: Template/typename problem.......one for the gurus!

    Thanks for your reply Paul.

    I have inherited a project which was written for PPC2003 (eVC4) and I have converted it to Visual Studio 2005. When I build it I get the error messages above for the code I have shown above. The code has not changed at all.

    For the error message C4346 in MSDN help it says that
    "The typename keyword is required if a dependent name is to be treated as a type. This is a breaking change in the Visual C++ .NET 2003 compiler, made in order to conform to the ISO C++ standard"

    So I'm thinking that there has been a change in the way typenames have to be declared since eVC4. But I do not know how or what It must be changed to. The file 'stl_alloc.h' is 3rd party freeware code which I did not write.

    Have u any suggestions?

    Thanks again.

    Harry.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Template/typename problem.......one for the gurus!

    Quote Originally Posted by Harry123
    So I'm thinking that there has been a change in the way typenames have to be declared since eVC4. But I do not know how or what It must be changed to. The file 'stl_alloc.h' is 3rd party freeware code which I did not write.
    You don't need the third-party STL library for Visual Studio 2005. Remove it from your project and use the STL that comes with Visual Studio 2005.

    It looks like you are using STLPort or another version of STL, found here:
    www.stlport.org

    The one you used is specially written for the older compiler, not for Visual Studio 2005. Since Visual Studio 2005 has the STL library included, there is no need for you to be using the third-party library.

    Unless there is something wrong with the STL that comes with your compiler, or you have a valid reason to be using STLPort, just use the STL that is included with the compiler.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Dec 2006
    Posts
    18

    Re: Template/typename problem.......one for the gurus!

    Thanks Paul for your reply.

    Sorry for the 'stupid' questons but I'm learning.....

    The project that I have has a folder called 'stl' and all the stl files are in here. How do I change my project, which has now been converted to Visual Studio 2005, to not use this stl but use the one that comes with it?

    I have looked in the project settings but I can't seem to find anything.

    Thanks once again.

    harry

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Template/typename problem.......one for the gurus!

    Quote Originally Posted by Harry123
    Thanks Paul for your reply.

    Sorry for the 'stupid' questons but I'm learning.....

    The project that I have has a folder called 'stl' and all the stl files are in here.
    The easiest thing for you to do, believe it or not is to get rid of that stl folder from your project. Just nuke it, delete it, whatever -- the Visual Studio 2005 compiler shouldn't be even taking a sniff of that third-party STL.

    When you recompile your program, you will probably get other errors that certain STL classes are functions can't be found. In that case, the issue is that you're not pointing to the compiler's header directory, or your source code still has something like:
    Code:
    #include "thirdpartystl\stl_header"
    Then you need to include the actual standard header, instead of the third-party STL header.

    Here is a sample of a valid C++ program that uses STL:
    Code:
    #include <string>
    #include <vector>
    #include <iostream>
    
    using namespace std;
    int main()
    {
       vector<int> IntVect(10);
       IntVect[0] = 1;
       string s = "Hello World";
       cout << s;
    }
    This should compile with no problems with Visual Studio 2005. The issue that you are having is that standard C++ headers such as <vector>, <string> were not created for the eVC4 compiler. So that is why whoever had the project previously needed to use a third-party STL product.

    Now that STL is part of standard C++, it comes with every standard C++ compiler, including Visual Studio 2005. For Visual Studio 2005, you don't need to set anything to use STL. Just write the code, compile, and run. The problem you're having is that your project still points to and uses the third-party evc4 version of STL. So that is why I stated you should just get rid of that STL, compile, and fix any errors.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Dec 2006
    Posts
    18

    Re: Template/typename problem.......one for the gurus!

    Thanks a million Paul. I deleted the old stl folder and although I am getting some error messages at least they are ones that I can work through now.

    Thanks again for all your help.

    Harry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)