|
Don't know...
Regarding to typename CString specifically, it works well with my VC++.NET v7.0. I had tested the code snippet before I posted the previous post. And the code compiles well without any error / warning!
Maxwell Chen
|
|
|
|
|
Hmm. You're right. Your code's working on VS.NET2003 as well. Perhaps it's an incompatability between CString implementations? Or maybe he's using VC6, and it's failing to match the standards in this area.
|
|
|
|
|
In VC++6, it's an ordinal class CString.
In VC++7.x, it's a class template CStringT<typename N>. And typedefed CStringT<char> as CString.
Maybe that's the cause...
Maxwell Chen
|
|
|
|
|
Apparently so. I guess I'm not quite clear on what counts as a polymorphic type, though. Maybe templates are special or something, but I couldn't find any virtual functions in CString or its superclass. It seems to me that it still shouldn't qualify as a polymorphic type, and therefore dynamic_cast shouldn't work.
|
|
|
|
|
yes i am using vc++6.0
i will try the typeid method once i re-write all my lost codes
My initial intention was to come up with a global class that can convert
a variable of type A to type B at run-time.
|
|
|
|
|
Remember to turn on the RTTI (run-time type information) option in VC++ project setting.
Maxwell Chen
|
|
|
|
|
aaaaahh...
thats what they mean by run time type information !!!
haha.
|
|
|
|
|
What vc 7.x is doing seems more logical than vc 6.0 ...
it seems to be checking the "from" and "to" types!
class A {
int a;
};
class B: public A {
int b;
};
/***** break ****/
B b;
if (dynamic_cast<B *>(&b)) {
printf("OK");
}
/***** above will work in vc 7.x but not vc 6.0 */
/***** below will NOT work in both vc 7.x & vc 6.0 */
B b;
A *p_a = &b;
if (dynamic_cast<B *>(p_a)) {
printf("OK");
}
|
|
|
|
|
If you already have the variable, as opposed to a pointer or a reference to a variable, you already know the type of the variable, so I'm not quite clear on why you even need to check this at all.
If you can post a code snippet showing what exactly you are trying to do, I'm sure someone could give you an exact answer. At least tell us what m_variable is declared to be? Is it a CString, or a pointer to a CString, or a void pointer, or something else?
|
|
|
|
|
my source file is gone ! (not in Recycle Bin, My Computer, anywhere...)
for some reason, my source file has disappeared (although the header file is still there). Could it be because I wrote
#include "MyGlobals.h" in stdafx.h ?
I've been using extern to make everything in MyGlobals.cpp available
everywhere - and it worked so well for so long... up until I started messing around with dynamic_cast.
has this happened to anyone before ?
(in extreme doh)
|
|
|
|
|
I'd say run a system-wide search for the file just to make sure you didn't accidentally drag-and-drop it into another folder somehow.
If that doesn't turn it up, it's probably gone for good. I suppose you could try some file-recovery software. But I've had little success with that in the past.
I'd also run a system-wide virus scan. If it's really gone, something deleted it. It's unlikely that it's a Windows or hardware problem. (Might be worth checking the event viewer in Administrative Tools, though, just in case.)
After that, I guess you get to start over if you didn't recover it. Sucks, but it happens. (This is why everyone talks about backups, though I don't believe most actually do so on a regular basis.)
|
|
|
|
|
I used to zip my source code files (removed those .ncb, .opt, .plg, .\Debug, etc.) with separate file names (timestamp + hint) quite often to prevent such disasaters.
Maxwell Chen
|
|
|
|
|
When you get going again, maybe you could try a template specialisation, which avoids the need for typeid or dynamic_cast's by making the compiler do the work for you.
This specialisation is so simple that it should work even under VC6
template<class T>
void f(T t)
{
}
template<>
void f<CString>(CString t)
{
OutputDebugString(t);
}
int i = 0;
f(i);
CString str = "hello world";
f(str);
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
did you try typeid () ??
TOXCCT >>> GEII power
|
|
|
|
|
For non RTTI way
You could try
IsKindOf
(Of course, this is not as good as RTTI. As this was invented by Microsoft
before the time where RTTI was approved by ANSI.)
For RTTI
you could try type_info or the one they mentiond dynamic_cast..
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
For MFC objects, have you looks at IsKindOf() ?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
i'm starting with MFC and drawing
i want to draw a consistent line when i click the mouse (with the function OnMouseMove). i tried with this, but it's not quite the result i want.
<br />
CClientDC dc(this);<br />
dc.MoveTo(point.x,point.y);<br />
dc.LineTo(point.x+1,point.y+1);<br />
this is also not nice:
<br />
CClientDC dc(this);<br />
dc.Rectangle(point.x,point.y,point.x+2,point.y+2);
any ideas?
thanks!!!
|
|
|
|
|
You need to remember each time the last point you drew to, and draw a line from the old point to the new point. I have a program here on CP that does it in GDI+, called doodle, from memory.
Man, that was a long time ago.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
well, i tried with this code:
<br />
CClientDC dc(this);<br />
if ((p.x!=0)&&(p.y!=0))<br />
{<br />
dc.MoveTo(point.x, point.y);<br />
dc.LineTo(p.x,p.y);<br />
}<br />
dc.MoveTo(point.x, point.y);<br />
dc.LineTo(point.x+1, point.y+1);<br />
p=dc.GetCurrentPosition();<br />
p is a CPoint variable that i added to the class, and in the constructor i initialize it with zero.
The problem is that when i draw by moving the mouse while it is clicked, and then i unclick the mouse, if i click it again somewhere else, it draws a line from the last point where i clicked to the new position.
any ideas?
thanks!
|
|
|
|
|
Sure. Make that check if p.x and p.y are equal to negative one ( 0 is surely an acceptable value ) and set them both to negative one when the mouse button is raised.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
THE QUESTION REQUIRES US TO DESIGN A FUNCTION AS MENTIONED BELOW, AND EVERYTIME I DEBUG THE PROGRAM, IT GIVES ME ONLY ONE ERROR WHICH IS MENTIONED RIGHT AT TEH BOTTOM OF THE PAGE.
//Purpose::TO CONVERT A GIVEN SIX DIGIT INTEGER TO DATE FORMAT (dd/mm/yyyy)AND CHECK Y2K COMPLIANCE
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
int D,DD,MM,YY;
void separateDate(int *temp,int *DD,int *MM,int *YY)
{
*DD=*temp/10000;
*MM=(*temp%10000)/100;
*YY=(*temp%10000)%100;
do
{
Console::WriteLine(S"\nEnter a Valid Date: ");
}
while (*DD<1 || *DD>31);
do
{
Console::WriteLine(S"\nEnter a Valid Date: ");
}
while (*MM<1 || *MM>12);
if (*YY<=36)
{
Console::WriteLine(S"\nTHE DATE IS: {0}/{1}/20{2}",*DD.ToString(),*MM.ToString(),*YY.ToString()); //h:\Visual Studio Projects\Y2k\Y2K.cpp(28): error C2228: left of '.ToString' must have class/struct/union type
}
else
if (*YY>36)
{
Console::WriteLine(S"\nTHE DATE IS: {0}/{1}/19{2}",*DD.ToString(),*MM.ToString(),*YY.ToString()); //h:\Visual Studio Projects\Y2k\Y2K.cpp(28): error C2228: left of '.ToString' must have class/struct/union type
}
}
int _tmain()
{
Console::WriteLine(S"*******************************************************************");
Console::WriteLine(S"\t\tDATE FORMAT");
Console::WriteLine(S"*******************************************************************");
void separateDate(int *temp, int *DD, int *MM, int *YY);
Console::Write(S"\nENTER THE DATE (SIX DIGIT POSITIVE INTEGER): ");
D=D.Parse(Console::ReadLine());
separateDate(&D,&DD,&MM,&YY);
Console::ReadLine();
return 0;
}
//h:\Visual Studio Projects\Y2k\Y2K.cpp(28): error C2228: left of '.ToString' must have class/struct/union type
I HAVE ALSO MENTIONED THE ERROR IN THE LINES IT OCCURS, PLEASE HELP, AM IN A TIGHT SPOT!! THANKS
|
|
|
|
|
The problem is that the int C++ type is used, and it isn't a struct/class. You should use the System::Int32 type if you want to use the .ToString method.
#include "stdafx.h"<br />
#using <mscorlib.dll><br />
using namespace System;<br />
<br />
System::Int32 D,DD,MM,YY;<br />
void separateDate(System::Int32 *temp,System::Int32 *DD,System::Int32 *MM,System::Int32 *YY)<br />
{<br />
*DD=*temp/10000;<br />
*MM=(*temp%10000)/100;<br />
*YY=(*temp%10000)%100;<br />
do<br />
{ <br />
Console::WriteLine(S"\nEnter a Valid Date: ");<br />
}<br />
while (*DD<1 || *DD>31);<br />
do<br />
{<br />
Console::WriteLine(S"\nEnter a Valid Date: ");<br />
}<br />
while (*MM<1 || *MM>12);<br />
<br />
if (*YY<=36)<br />
{<br />
Console::WriteLine(S"\nTHE DATE IS: {0}/{1}/20{2}",(*DD).ToString(),(*MM).ToString(),(*YY).ToString());<br />
}<br />
else<br />
if (*YY>36)<br />
{<br />
Console::WriteLine(S"\nTHE DATE IS: {0}/{1}/19{2}",(*DD).ToString(),(*MM).ToString(),(*YY).ToString());<br />
}<br />
}<br />
int _tmain()<br />
{ <br />
Console::WriteLine(S"*******************************************************************");<br />
Console::WriteLine(S"\t\tDATE FORMAT");<br />
Console::WriteLine(S"*******************************************************************");<br />
<br />
void separateDate(System::Int32 *temp, System::Int32 *DD, System::Int32 *MM, System::Int32 *YY);<br />
Console::Write(S"\nENTER THE DATE (SIX DIGIT POSITIVE INTEGER): ");<br />
D=D.Parse(Console::ReadLine());<br />
separateDate(&D,&DD,&MM,&YY);<br />
<br />
Console::ReadLine();<br />
return 0;<br />
}
Pablo Hernandez Valdes
|
|
|
|
|
People are doing beginner courses in MC++ now ? What a travesty....
By the way, PLEASE DON'T YELL !!!!
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I want to compare member variables that are in the derived class and not the base class.
Can I overload operator== for a derived class?? Or do I have to define one for the base class as well.
Thanks.
-C
|
|
|
|
|