Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-03-2006, 08:33 PM   #1 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 735
DJMaze is on a distinguished road
get classname

Does anyone know how to retrieve the class name in ISO C++?

class FooBar {
public FooBar() { print(__CLASS__); } ???
}
DJMaze is offline   Reply With Quote
Old 03-04-2006, 12:02 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
hmm.. why would you need that...
The only time I can see this come in handy, is when dealing with languages, where variables can be of ANY type, so you'd want to do some sort of switch on the class.
At all times, unless you specific want it, the typechecker will make sure the class you're dealing with is of the correct type, so from my point of view it's a matter of redesigning your current situation.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-04-2006, 06:56 AM   #3 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 735
DJMaze is on a distinguished road
BCB has a function named ClassNameIs and more of those.
Since i'm moving to a cross-platform ISO C++ enviornment i need similar tasks.

This because i create dragdrop handlers that run a action based on the class name.

For example i have a filelist box and a database table and they both contain filenames. To drop a filename from one of these classes i need to know the class type since both have different methods to fetch them.

filelist->selected_index
table->cell[row][col]

Maybe i should just add the proposed addition predefined identifier from C99

class Window
{
public:
static const char __class__[] = "class name";
DJMaze is offline   Reply With Quote
Old 03-04-2006, 04:52 PM   #4 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
maybe you should make a file_drop method that is polymophic for the various widgets you need to handle, that way the compiler can switch on the class name for you.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 03-05-2006, 03:13 AM   #5 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 735
DJMaze is on a distinguished road
Doh that i didn't think of that, this cross-platform programming does blow my mind at the moment.
Thanks teknomage1
DJMaze is offline   Reply With Quote
Old 03-05-2006, 09:40 AM   #6 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
just glad I could be helpful for once!
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 03-06-2006, 03:10 PM   #7 (permalink)
kyoryu
Registered User
 
Join Date: Apr 2003
Posts: 34
kyoryu is on a distinguished road
The only problem with that is you either have to subclass each control for each instance on each form, or you end up with a TON of specific code in your generic UI element classes.

You should have access to a pointer to the specific objects on your form, either by some sort of functionality to get a pointer for an element by name, or by just having pointers to the elements directly. If you can get a pointer for a specific widget, you can check to see if the pointer for the object you're over is the same as the other one.

Additionally, if you want to see if an object is of a specific subclass, you can always use dynamic_cast< type >, assuming you've told it to compile with RTTI info.

What UI lib are you using?
kyoryu is offline   Reply With Quote
Old 03-07-2006, 06:12 PM   #8 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 735
DJMaze is on a distinguished road
I create many derivatives of my mywindow class.
Under Windows you need to register a WNDCLASS/WNDCLASSEX to get the mywindow to show.
Each instance has its own WNDPROC handler so things like buttons, grids, textedit classes are derivatives of the mywindow class.

If i need to find a certain window i use FindWindowEx and then SendMessage in some circumstances like disallowing second execution and pass on the commandline arguments.
BCB allowed me to do this easily because it compiled the instance name into the class.
Code:
TForm *MainWindow = new TForm();
FindWindowEx(NULL, NULL, "MainWindow", NULL);
Now in ansi i need to find a different way since finding a window/xwindow by the window title is not a option.
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 05:28 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting