473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy constructor (i think i have to use it...)

12 New Member
hii everyone!
i have a little problem in Java,
ok so i built a constructor and called it ToMe (it has some Strings),
after that i built his Copy constructor and later on i built a new constructor, called ToHim, now i want to make a new ToMe in the ToHim constructor but i have a problem, i wrote:

Expand|Select|Wrap|Line Numbers
  1. String abla
  2. public ToHim(String bla)
  3. {
  4. abla = bla;
  5. ToMe tome = new ToMe(a,b,c,d); 
  6. }
i mean that i wanted to make a new ToMe (calls "atome") outside the constructor and write the next unpossible line:

Expand|Select|Wrap|Line Numbers
  1. atome = ToMe tome = new ToMe(a,b,c,d); 
i think i have to use the Copy constructor but i don't know how...

thanks alot!
Mike
Nov 10 '07 #1
1 1069
r035198x
13,262 MVP
hii everyone!
i have a little problem in Java,
ok so i built a constructor and called it ToMe (it has some Strings),
after that i built his Copy constructor and later on i built a new constructor, called ToHim, now i want to make a new ToMe in the ToHim constructor but i have a problem, i wrote:

Expand|Select|Wrap|Line Numbers
  1. String abla
  2. public ToHim(String bla)
  3. {
  4. abla = bla;
  5. ToMe tome = new ToMe(a,b,c,d); 
  6. }
i mean that i wanted to make a new ToMe (calls "atome") outside the constructor and write the next unpossible line:

Expand|Select|Wrap|Line Numbers
  1. atome = ToMe tome = new ToMe(a,b,c,d); 
i think i have to use the Copy constructor but i don't know how...

thanks alot!
Mike
You realize that constructors must have the same name as their class.
Read this article which talks a bit about constructors.
Nov 10 '07 #2

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

Similar topics

42
5720
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
15
21173
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
9
2725
by: muzmail | last post by:
I have declared a copy constructor for a template class in a Visual C++ project but for some reason the compiler ignores it. I can put syntax errors in the copy constructor and the compiler ignores...
10
2526
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, ...
27
3355
by: JoeC | last post by:
I am still working on my game and my program is getting better. Most of what I want to works. I think I am having trouble with copy constructor. Basically I want it to copy the gdata array. My...
8
4288
by: shuisheng | last post by:
Dear All, I am wondering how the default copy constructor of a derived class looks like. Does it look like class B : public A { B(const B& right) : A(right) {}
10
2596
by: dragoncoder | last post by:
Hi all, I am trying to understanding std::auto_ptr<Tclass implementation from "The C++ standard library" by Nicolai Josuttis. He gives a sample implementation of auto_ptr class template in...
7
1720
by: Claudius | last post by:
Hello, in my class TopTen I need to define three constructors while only the last one, the most general in terms of templates, should be sufficient in my opinion: template <typename Tnum,...
22
3587
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
10
1868
by: abhash | last post by:
I am bit puzzled at the following piece of code I tried: ---------------------------------------------------------------------------------- #include <iostream> using namespace std; class Test...
0
7220
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
7308
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
7371
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...
0
5617
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
5037
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
4702
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
3188
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
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.