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.ReadLin e.
Then I created an object.
Contact objContact = new Contact(firstNa me, 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.getF irstName(); objContact.getL astName();
objContact.getP hone(); objContact.getE mail();
}
I get error:
Cannot implicitly convert type 'string' to 'program3.Conta ct'
what am I doing wrong?
1 1556 AdrianH 1,251
Recognized Expert Top Contributor
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.ReadLin e.
Lookup: istream& getline( istream& is, string& s, char delimiter = '\n' ); located in strings.
Then I created an object.
Contact objContact = new Contact(firstNa me, 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.getF irstName(); objContact.getL astName();
objContact.getP hone(); objContact.getE mail();
}
I get error:
What? Only one? ;)
Cannot implicitly convert type 'string' to 'program3.Conta ct'
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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, piece types, squares,
etc.). To accomplish this, I used implicit conversions. For instance, a
color used to be:
typedef int Color;
// and a few constants...
Now a color is (paraphrased):
|
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 implicit conversion
for this case, however if instead of class X we just use a pointer
then the implicit conversion will work.
Anyone have any ideas why it will not do implicit conversion?
|
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 Test. I
expected the same error from the following line, but it compiles fine.
The double is silently truncated to an int and then fed in to the
implicit conversion operator. Why does this happen? Is there any way
that I can keep the implicit...
|
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 emulate the pattern im trying to follow in an
existing project.
These are my steps:
1) I have a method "printMe" existing in the application which originally
used to take in a string. This method is static and sits in the Driver
|
by: Aaron Queenan |
last post by:
Given the classes:
class Class
{
public static implicit operator int(Class c)
{
return 0;
}
}
class Holder
| |
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 in
a C# program but not VB?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
|
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 set a property on a class that takes an interface instance.
I have a class that can cast implicit to a class that impliments said
interface,
but the compiler moans and says it cannot cast implicitly like that.
|
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>
#include <iostream>
#include <cstring>
int main(){
|
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 it's
Selected value like this : SelectedValue='<%# Bind("TaxCondition")
%>'. In this case, TaxCondition is an int, and the conversion from int
to string and string to int is made automatically.
|
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 functions, like Normalize(). The problem
is Vector cannot use any of the Point operator overloads with a compile
time error that there is no implicit conversion from Point to Vector. I
tried adding an implicit operator to Vector:
public static implicit...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |