473,503 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class to basic type?

1 New Member
how to type convert class to basic type in c++?
Sep 16 '07 #1
2 2352
Ganon11
3,652 Recognized Expert Specialist
You mean, say, converting a Plant class to a char?

It really can't be done...or, at least, shouldn't. What exactly are you trying to accomplish with this type conversion?
Sep 16 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
You write a conversion operator.

Suppose you had a Date class with ints for month day and year. You could convert a Date obejct to a const char* by:

Expand|Select|Wrap|Line Numbers
  1. Date::operator const char*()
  2. {
  3.    delete this->result;
  4.    this->result = new string;
  5.    *(this->result) + this->month;
  6.    *(this->result) + "/";
  7.    *(this->result) + this->day;
  8.    *(this->result) + "/";
  9.    *(this->result) + this->year;
  10.    return this->result->c_str();
  11. }
  12.  
where result is a string*.

Once you do this, you can use a Date as a const char*. Assuming, that is, that the string layout is taken into account.
Sep 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2122
by: E G | last post by:
Hi! I am having problems in designing a class. First, I have a base class that allocates a 3D data set and allows some other mathematical operations with it, something like this: template...
9
4960
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
1
1232
by: Bob | last post by:
Try the following code class basic { public: virtual void one()=0; }; class derived1:public basic { public:
3
1798
by: fernandez.dan | last post by:
I'm still learning how to use Object Oriented concepts. I'm have a basic question dealing with design. I have two classes that deal with I/O pertaining to network and usb that inherit from an...
29
1944
by: Michael D. Ober | last post by:
Is there any way to create a constant in a class that can be used both with an instantiated object and without. For example: dim ClassConst as string = myClass.ConstantString dim myObj = new...
36
2057
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a...
3
2031
by: Simon Hart | last post by:
Hi, I am trying to implement some functionality as seen in MS CRM 3.0 whereby a basic Xml is deserialized into an object which contains properties. What I want to do from here is; cast the basic...
2
697
by: she_prog | last post by:
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from...
5
2469
by: christian.pontesegger | last post by:
Hi all, lately I had a problem where I wanted to cast a basic class to a derived type, which did not introduce any new members and did not change any stuff with dynamically allocated memory. I...
30
1872
by: Logos | last post by:
I have what may be a bug, or may be a misunderstanding on how pass by reference and class inheritance works in PHP. Since I'm relatively new to PHP, I'm hoping for a little outside help to shed...
0
7194
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
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5566
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,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
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...
0
3160
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
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...

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.