473,466 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

implicit constructor

Hi Everyone,

I know that implicit conversion is invoked for the following case,

class A
{
public: A(int n)
{
...
}
};
A obj = 2;

But is any temp objects created? Is the 2 used to create a temp
object and then is the temp object assigned to the the actual object
obj?

Thanks in advance!!!

Oct 30 '07 #1
2 2198
Rahul wrote:
Hi Everyone,

I know that implicit conversion is invoked for the following case,

class A
{
public: A(int n)
{
...
}
};
A obj = 2;

But is any temp objects created? Is the 2 used to create a temp
object and then is the temp object assigned to the the actual object
obj?
The semantics are such that a temporary object is created. However,
the Standard allows the compiler to forgo creation of a temporary in
such case and construct 'obj' as if you wrote

A obj(2);

The copy-constructor in 'A' has to still be accessible, though.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 30 '07 #2
Rahul wrote:
Hi Everyone,

I know that implicit conversion is invoked for the following case,

class A
{
public: A(int n)
{
...
}
};
A obj = 2;

But is any temp objects created? Is the 2 used to create a temp
object and then is the temp object assigned to the the actual object
obj?
It's not assigned, but rather copy-constructed. Apart from that, see
Victor's answer.

Oct 30 '07 #3

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

Similar topics

9
by: sb | last post by:
If there is at least one user-defined constructor, no constructors are implicitly declared. struct my_vec : public vector<int> { double foo; my_vec(size_t n) : vector<int>(2*n) {} // oops, no...
4
by: Master of C++ | last post by:
Hi, This is a simple question. In the following example, .. class Vector .. { .. private: .. int *Numbers; .. int vLength; ..
5
by: JezB | last post by:
Is there any way in a generic class object to implicitly get a reference to the class that instantiated that object ? Obviously I can pass it a reference to store but it would be nice if there was...
25
by: Chad Z. Hower aka Kudzu | last post by:
I have defined some implicit convertors so that I can do: MyStruct x = 4; The implicit convert the 4 into MyStruct. But its essentially a copy constructor and thus if I had: MyStruct x;...
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
1
by: flopbucket | last post by:
Hi, If I have: template<class T> class X { ..... };
9
by: Alex Vinokur | last post by:
Compiler Green Hills C++, Version 4.0.6 --- foo.cpp --- struct A { }; struct B { B() {}
3
by: bb | last post by:
Hi, Please could you clarify why 'implicit conversion' does not take place while assigning an iterator to reverse_iterator. However, it happens while initializing/constructing. e.g. typedef...
3
by: Jess | last post by:
Hello, I can perform implicit conversion through constructor, like class A{ public: A(int x):a(x){}; int a; };
3
by: utab | last post by:
Dear all, I was trying to write a more complex program, and while searching for sth in my reference C++ primer, by Lippman. I had a question in the mind, see the code below #include <string>...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.