CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 1999
    Location
    Miami, FL
    Posts
    972

    using auto_ptr (only)

    I use the auto_ptr template class in my code in several places. I'd like to use it without the std:: qualifier so I have two choices: 1, bring in the whole std namespace with the using directive; or 2, bring in just the auto_ptr class with the using declaration.

    My question is, what's the proper way to do the second option? I've tried doing this:


    #include <memory>
    using std::auto_ptr<class T>;



    This compiles fine but then when I say:

    auto_ptr<CFile> pFile;



    the compiler tells me: 'auto_ptr' : undeclared identifier.

    What am I doing wrong?

    Thanks,
    Alvaro



  2. #2
    Guest

    Re: using auto_ptr (only)

    I'd like to know the answer too!


  3. #3
    Guest

    Re: using auto_ptr (only)

    A using declaration brings in a name. It doesn't matter if the type is incomplete, or if the name is even a type.

    You want:

    #include <memory>
    using std::auto_ptr;
    auto_ptr<CWnd> pToWindow; // works



    Later,
    Chris Tracy
    [email protected]


  4. #4
    Join Date
    Jun 1999
    Location
    Miami, FL
    Posts
    972

    Re: using auto_ptr (only)

    Hi Chris,

    I tried it but the compiler complained on the using line saying:

    error C2955: 'auto_ptr' : use of class template requires template argument list

    Thanks for your response,
    Alvaro


  5. #5
    Join Date
    Sep 1999
    Location
    NJ
    Posts
    1,299

    Re: using auto_ptr (only)

    I hadn't seen that problem since VC5, so I suspect that the "correct" answer is to upgrade to VC6sp3.

    Until then, I believe either:

    using std::auto_ptr<CFile>
    or
    using namespace std;

    should work.


    Truth,
    James
    http://www.NJTheater.com
    http://www.NJTheater.com/JamesCurran

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured