473,398 Members | 2,380 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,398 software developers and data experts.

Implicit Conversion -

thav
6
I'm taking an intro class right now , I'm not having any fun so far. I keep getting implicit conversion. I tried everything from .toString and declaring the array as a string which gives me problems later down when using a foreach statement later on. Can anyone point me in the right direction?

I created an Array.

Contact[] Contacts = new Contact[1];

and I am getting string input from users, using the Console.ReadLine.

Then I created an object.

Contact objContact = new Contact(firstName, lastName, phone, email);


that has those properties from the input.

then I want to add those input into my Contact array.

for (int i = 0; i < Contacts.Length; i++)
{
Contacts[i] = objContact.getFirstName(); objContact.getLastName();
objContact.getPhone(); objContact.getEmail();
}


I get error:
Cannot implicitly convert type 'string' to 'program3.Contact'

what am I doing wrong?
Mar 26 '07 #1
1 1543
AdrianH
1,251 Expert 1GB
I'm taking an intro class right now , I'm not having any fun so far. I keep getting implicit conversion. I tried everything from .toString and declaring the array as a string which gives me problems later down when using a foreach statement later on. Can anyone point me in the right direction?

I created an Array.

Contact[] Contacts = new Contact[1];
You are programming as you would in Java. This is C/C++. Try either: Contract* Contrats[] = { new Contract() }; or Contract* Contracts = new Contract[1];

and I am getting string input from users, using the Console.ReadLine.
Lookup: istream& getline( istream& is, string& s, char delimiter = '\n' ); located in strings.

Then I created an object.

Contact objContact = new Contact(firstName, lastName, phone, email);


that has those properties from the input.

then I want to add those input into my Contact array.

for (int i = 0; i < Contacts.Length; i++)
{
Contacts[i] = objContact.getFirstName(); objContact.getLastName();
objContact.getPhone(); objContact.getEmail();
}


I get error:
What? Only one? ;)
Cannot implicitly convert type 'string' to 'program3.Contact'

what am I doing wrong?
Pretty much everything. ;)

In C and C++ there is no length attribute. To get the size of an raw array in C/C++, that is declared on the stack or in a class, you can use this trick: int const size = sizeof(Contacts)/sizeof(Contacts[0]);

However, if you try and allocated an array like this: Contact * Contacts = new Contact[10];, that trick will not work. The best thing to do is use a vector.

If you posted this in error, then please state and I'll move this over to the Java forum.

Hope this helps.


Adrian
Mar 27 '07 #2

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

Similar topics

2
by: Russell Reagan | last post by:
In a newer version of a chess program I am writing, I have created classes that are (more or less) drop in replacements for things that used to be plain old integer or enumerated variables (colors,...
1
by: Christophe Poucet | last post by:
Hellom I have an issue with implicit conversions. Apparently when one calls an operator on a class Y which has a conversion operator to class X which has the operator . Sadly it will not do...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
9
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
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...
10
by: Pieter Breed | last post by:
Hi All, Please excuse me, but the bulk of my post will be a code post. It describes some weirdness with regards to the implicit casting operator. The crux of the problem is this: I want to...
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: drop | last post by:
Hi all, I'd like to know if it's possible to declare an implicit type conversion for when I use declarative Synthax in html. For example, when I have the DropDownList, I can declatively set...
8
by: jonpb | last post by:
Hi, Is it possible to define a implicit operator from base to derived types in C#? I have a Point class and would like to derive a Vector class from it and add a couple new vector related...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.