I learn C++ and COM through the books.
In the IDE MS Visual Studio 2012 I have created new empty C++ project, and added some existing files to it. My CPP file contains #include<iostream> row, but in editor I got such messages:
Error: identifier "cout" is undefined
end
Error: identifier "endl" is undefined
Code:
#include<iostream>
#include"interfaces.h" // unknown.h, objbase.h, initguid.h
class CA {//: public IX, IY{
public:
// Constructor
CA();
// Destructor
~CA();
// IUnknown
virtual HRESULT __stdcall QueryInterface(const IID& iid, void** ppv);
virtual ULONG __stdcall AddRef();
virtual ULONG __stdcall Release();
// IX
virtual void __stdcall Fx1();
virtual void __stdcall Fx2();
// IY
virtual void __stdcall Fy1(){ cout << "Fy1" << endl; } // errors here
virtual void __stdcall Fy2(){ cout << "Fy2" << endl; } // errors here also
private:
long counter;
};
Why it happens?
You need to specify the
std::namespace:Alternatively, you can use a
usingdirective:I should add that you should avoid these
usingdirectives in headers, since code including these will also have the symbols brought into the global namespace. Restrict using directives to small scopes, for exampleHere, the
usingdirective only applies to the scope offoo().