Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Style Casting in c++? 1

Status
Not open for further replies.

Dannybe2

Programmer
Jan 31, 2001
136
0
0
GB
I'm using Visual Studio 7.0, and it doesn't seem to be recognizing casting with the <> brackets. I know this was introduced in java 1.5, but I don't know about c++.

The problem is it's not working with the new Microsoft BDA stuff, which is essential for me to get it working with.

Does anyone know if it was introduced in .Net framework 1.1 of not, as despite having version 1.1, it says I only have 1.0 in visual studio.

Anyone?
 
What is it: new style casting in C++?
As far as I know there three explicit type conversions in C++ Standard: via functional notation t(v), conversion operators (const_cast<..>() et al) and old cast notation (t)v. What else?..
What for Java reference here?..
 
Well, I'm less familiar with c++.

But for java, the dynamic casting like Object <String> ...
that was introduced only recently to allow users to simplify the following stages by eliminating the casting for objects within collections and such like.

I expected the same was true for c++ and that I didn't have the correct version which is why it was creating an error on compilation.

Let me describe the exact error, which might help to illustrate the problem.

When compiling, I get errors indicating that the syntax on every line such as the following one is incorrect:

typedef CComQIPtr<ITuningSpaceContainer> PQTuningSpaceContainer;

It picks up the '<', saying it was expecting an end of line...
 
That isn't casting, it's using a template.
To cast, do this:
Code:
const int i = 3;
i = const_cast<int>( 5 );  // modify a const variable.

CBaseClass* pBase = SomeFunc();
CDerivedClass* pDerived = dynamic_cast<CDerivedClass*>( pBase );  // try to cast a base class to a derived class.

CDerivedClass derived;
CBaseClass* pBase = static_cast<CBaseClass*>( &derived );  // simple cast to a related type.

int i = 4;
int* pInt = &i;
char* pszString = reinterpret_cast<char*>( pInt );  // cast to an unrelated type.

To use a template, you do something like this:
Code:
std::list<int> intList;  // A list of ints.
std::list<float> floatList;  // A list of floats.
 
Yes, you're right it is a template.

But, it's still a template written by Microsoft, so I don't want to change any of the code, I just want to know if there is a certain something I haven't installed that is essential to get this to work.
 
Looks like you're missing a template parameter. The definition is:
Code:
template< class T, const IID* piid >
class CComQIPtr
You only passed one parameter in the <> list.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top