Click to See Complete Forum and Search --> : using auto_ptr (only)


ALM
October 20th, 1999, 09:54 AM
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

October 20th, 1999, 05:04 PM
I'd like to know the answer too!

October 20th, 1999, 05:15 PM
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
crtracy@uiuc.edu

ALM
October 20th, 1999, 05:24 PM
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

James Curran
October 26th, 1999, 09:41 AM
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