Tag Archives: namespace

CA2W found

Here’s a problem that was driving me crazy for a while. I got the following error trying to use ATL’s CA2W class in a C++ program:

error C3861: ‘CA2W’: identifier not found

Usually problems like this occur when you don’t include the correct header file. But in this case, I did include it (atlconv.h), exactly like the documentation says.

I made sure that CA2W is really defined in the header. I checked other things, but the result was always that the compiler should have seen the definition. Still the nefarious error message appeared. So why did the compiler pretend not to know this symbol? Finally I saw this line at the beginning of atlconv.h:

namespace ATL
{

D’oh!

So CA2W did exist, but only in the ATL namespace. I never noticed this before; it turns out that by default projects created with Visual C++ include atlbase.h which does “using namespace ATL”. Including this file solved the problem.

The documentation says nothing about this, of course. I couldn’t find any mention of the word “namespace” in there.

Incidentally, looks like we’ll be seeing this problem a lot in the future since the default has changed in Visual Studio 2010.