473,769 Members | 6,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Implementing isInstanceOf(.. .) in c, any ideas

Hi,

I am thinking about implementing isInstanceOf() in c.
Any ideas ???

Ex.

int findType(struct x)
{
struct X orgX;
if (isInstanceOf(x , orgX))
return 1;
else
return 0;
}

main()
{
struct Y x;
int val=0;
val=findType(x) ;
}

Regards,
Abhishek

Jul 10 '06 #1
3 2455

dwaach wrote:
Hi,

I am thinking about implementing isInstanceOf() in c.
Any ideas ???

Ex.

int findType(struct x)
{
struct X orgX;
if (isInstanceOf(x , orgX))
return 1;
else
return 0;
}

main()
{
struct Y x;
int val=0;
val=findType(x) ;
}

Regards,
Abhishek
Well, there's always RTTI...

Jul 10 '06 #2
I am thinking about implementing isInstanceOf() in c.
Any ideas ???
Post in comp.lang.c instead of c++ ? :)

Jul 10 '06 #3
"dwaach" <xb************ **@gmail.comwro te in message
news:11******** *************@h 48g2000cwc.goog legroups.com...
: I am thinking about implementing isInstanceOf() in c.
: Any ideas ???
C has no built-in concept of classes or instances,
so the answer would depend on how you choose to emulate
that feature.
In C++, dynamic_cast can be used to find if an object
is of a given subclass. You could write isInstanceOf
as follows:
template<class D, class B>
bool isInstanceOf(co nst B& b)
{ return !! dynamic_cast<co nst D*>(&b); }

Usage example (using <fstream>):

bool isFileOutput(st d::ostream& o)
{
return isInstanceOf<st d::ofstream>(o) ;
}

--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com
Jul 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
6473
by: Vadim Zima | last post by:
How would you approach this task? I have a phpBB forum on my site. The majority of participants are Russians living in the US, who don't know Russian keyboard layout. Is it possible to provide them with some sort of a button, in the posting edit window to convert latin characters into cyrillic characters? TIA for any ideas and/or links. -- Vadim Zima Certified Russian Translator/Conference Interpreter
3
1619
by: Gabriele Farina | last post by:
I guys I planned to create a new programming language to use to develop web applications for my company. I'd like to develop it using Python, but I don't know if python is fast enaught. Someone could help me and give me some ideas?
0
990
by: Scott Ure | last post by:
Hi, I am trying to implement my own formatter that implements and adheres to the standards of the IFormatter interface. I have run into a bit of an issue trying to serialize classes that implement the ISerializable interface. Specifically, I don't know how to repopulate the members (via the special New constructor). The MSDN documentation for the FormatterServices.PopulateObjectMembers function claims that: "if the object implements...
2
2705
by: Dmitri Zhukov | last post by:
Hello everyone, I am implementing software which has a medium sized number of text strings (max 100K) which are represented in a listbox. I want user to be able to search the string by typing the first letters of the record and showing coinciding record if any (similar to quickserach functionality of Norton/Total commander). So i guess I need some kind of hasing algorithm to be able to find string by its prefix. Any recommendations?
3
6443
by: Charulatha Kalluri | last post by:
Hello folks, I'm on the lookout for project ideas for a C++ class. The project should: -Be a "fairly complex" application
3
4508
by: Ivan Neganov | last post by:
Hi, I have a custom subclass of System.IO.Stream type. I wonder how to correctly implement the IDisposable pattern in this situation. The parent Stream type apparently uses explicit interface implementation, and I could not find a way for my child type to override parent's IDisposable.Dispose() method. The intention was to clean up child's resources first,
3
1428
by: dwaach | last post by:
Hi, I am thinking about implementing isInstanceOf() in c. Any ideas ??? Ex. int findType(struct x)
3
2171
by: Jason Taylor | last post by:
I am wanting to learn C++, and am curious what my first program should be. I learned PHP by reading the docs as I wrote a news posting script. Any ideas on how I would go about starting my trek in C++?
4
2008
by: Ognjen Bezanov | last post by:
Hello All, I am a third year computer science student and I'm the process of selection for my final year project. One option that was thought up was the idea of implement my own version of the python interpreter (I'm referring to CPython here). Either as a process running on another OS or as a process running directly on the CPU. Now, I can't seem to find a decent source of information on the python
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.