473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2433

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.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.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(const B& b)
{ return !! dynamic_cast<const D*>(&b); }

Usage example (using <fstream>):

bool isFileOutput(std::ostream& o)
{
return isInstanceOf<std::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
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...
3
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. ...
0
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...
2
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...
3
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
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...
3
by: dwaach | last post by:
Hi, I am thinking about implementing isInstanceOf() in c. Any ideas ??? Ex. int findType(struct x)
3
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.