15,743,299 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View Javascript questions
View C++ questions
View Python questions
View Java questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by geoyar (Top 5 by date)
geoyar
10-Feb-12 14:30pm
View
Deleted
Thanks for reply.
1.You are right about virtual methods. Nobody is sure how the dynamic_cast is implemented, but some people hint that it is possible than the first entry in the vtable in some compilers is a pointer to the type info, that was set at compile time, and the dynamic_cast just uses the same vtables as virtual methods do
2. The example does not should be complete, but IMHO should show essentials. People wit very different levels of C++ skills will read it.
By a way, is the Child derived from Base?
3. Because the comparison is not shown, this post is about comparison of the template parameters only. So static_cast is not related to this post. After you have determined the template parameters are the same, you are free do what you want. I would remove the cast.
4.Your method of generating ID leads to different IDs for the same template parameter, because the OS might allocate different memory pages for the different instances of the app. Of course, they are constant inside the given app instance.
5. You are saying that your code is the fastest. Did you have any numbers?
geoyar
9-Feb-12 21:39pm
View
Deleted
1. You do not want to use run time type info (dynamic_cast), but you are actually using RTTI because you are using virtual functions. The call to the virtual function is resolved at run time: the app determines the dynamic type of the pointer to the base class and looks into the virtual functions table of the basic class. As you remember, if you have BaseClass* bPtr = new ChildClass<t>, the bPtr has a static type BaseClass* and dynamic type ChildClass<t>*.
2. The code you wrote has bugs: no virtual destructors, bool equal() never returns true, the child class has no ancestor.
3. If your intention is to compare types, why do you do a static_cast? Return true if ids are the same, and that's it.
4. In ClassID() you wrote:
static int id;
return (int)&id;
On 64bit system the address is 64 bit. If you truncate it, you can't guarantee uniqueness.
In my opinion, using the ID to compare class types is legit, but your implementation is deeply flawed.
geoyar
30-Jan-12 21:47pm
View
Deleted
I do not think it is safe and good. All code is based on assumption that somebody have assigned right IDs to both classes. What if the IDs are the same, but the child class is bigger than other (e.g has more data members)? You can't cast up the inheritance ladder, only down.
Because you are not using inheritance, the only sense it makes is to cast between instantiations for the different T of the same class template.
This is a case for using TypeLists and static_asserts.
Set the TypeList for types that allow casts. and overload the cast operator
like
template <typename t,="" typename="" t1=""> childClass<t> operator ()(const childClass<t1>)
and in body of that operator trow static_assert if the T1 is can't be casted to T
geoyar
9-Nov-11 13:01pm
View
Deleted
Yes I do:
typedef std::basic_string<tchar> string_t.
geoyar
18-Oct-10 21:20pm
View
Deleted
Reason for my vote of 2
Is it much easier to write DelegateCreateThread() than CreateThread(...)?
I do not agree.