answersLogoWhite

0


Best Answer

There are no objects in C, so you can't.

However, in C++ you can convert an integer to an object if the object's class exposes a public conversion constructor that accepts an integer argument. For example:

class X {

public:

X (int); // conversion constructor

// ...

};

How the conversion is implemented depends on the class designer. In the following example, a user can construct a complex number type from an integer:

class complex {

private:

double r;

double i;

public:

complex (double real, double imaginary): r {real}, i {imaginary} {}

complex (int real): r {real}, i {0.0} {}

// ...

};

Here, the implementation implicitly converts the integer to a double and assigns that value to the real representation and assigns the value 0.00 to the imaginary representation. This class may be used as follows:

complex c = 42; // e.g., c.r = 42.0, c.i = 0.0

If a conversion constructor is provided, a corresponding conversion assignment is usually provided as well:

class complex { private:

double r;

double i;

public:

complex (double real, double imaginary): r {real}, i {imaginary} {}

complex (int real): r {real}, i {0.0} {}

complex& operator= (int real) { r = real; i = 0.0; }

// ...

};

This class may be used as follows:

complex c {1.1, -3.14};

// ...

c = 42; // e.g., c.r = 42.0, c.i = 0.0

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you convert integer to objects in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you convert an integer into a text using C?

sprintf is the most common solution


How do you convert an int to object in java?

Java has auto-boxing introduced in Java 5 and converts ints to Integer objects as needed.Or you can explictly call Integer.valueOf(int) or new Integer(int) to return an Integer object with the value of the primitive int argument.Example:int i = 14; // i = 14Integer a = Integer.valueOf(i); // a = 14Integer b = new Integer(i); // b = 14or simplyInteger c = i;


Which is an example of visual basic objects?

dim a as integer dim b as integer dim c as integer dim d as integer private sub command1_click () a=-1 b=1 d=1 while (d<=10) c=a+b print c a=b b=c next d end sub


Is it possible to convert a string into integer without using any function in c?

Yes


How do you convert Temperature 950000000 to integer?

You cannot convert temperature to number; 950000000 is already an integer.


Can a union be used in c to convert an integer into a double?

No, but a typecast can: int n; double d; d= (double)n;


How do you convert integers in character using c?

In C, an integer and a character are the same thing, just represented differently. For example: int x = 65; printf("x = (int) %d, (char) %c\n", x, x) should print "x = (int) 65, (char) A" You can also use the atoi (ascii to integer) and itoa (integer to ascii) functions.


How do you print size of integer?

the size of an integer is determaind by using the function "sizeof(c)",here 'c' is any integer.


How do you convert an integer to a fraction?

Any integer can be expressed as a fraction with the numerator equal to the integer and the denominator equal to 1.


How do you convert integer to IPv6?

poo on your self and then you will convert integer to ipv6! jokes! fart on your self then you will be able to convert! and i am serious! to find the real answer give me your number we'll have something private


What is the code required to convert an integer variable to a string variable in Java?

There are several different methods to convert an integer variable to a string variable in Java. For example, one can use the following code to convert an integer variable to a string variable: Integer.toString(number)


Which is the function which destroys objects in C?

No objects in C. For C++, it is destructor.