473,657 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: does not contain constructor with 0 arg issues. Can someone help me out?

Michael Tristan
2 New Member
I'm not sure what I am doing wrong, but I am trying to create a new object and it gives me the error that it does not contain a constructor with 0 arguments. I understand that the way I am writing it causes it to appear like it's parameterless, but I do not know how to fix it. The ultimate goal is to create a series of orders that will display to the screen with the details. I only have one order information set up, Ben Franklin's order, but intend on having more. Here is my code:

Expand|Select|Wrap|Line Numbers
  1.  public class Order
  2.     {
  3.         private int orderNum;
  4.         private string custName;
  5.         private int quantOrdered;
  6.         private int totalPrice;
  7.         private double price = 19.95;
  8.  
  9.         public Order(int ordNum, string name, int quantity)
  10.         {
  11.             OrderNum = ordNum;
  12.             CustName = name;
  13.             QuantOrdered = quantity;
  14.         }
  15. public override string ToString()
  16.         {
  17.             return ("Order Number: " + OrderNum + "Customer Name: " + CustName + "Quantity Ordered: " + QuantOrdered + "Total Price: " + TotalPrice.ToString("C"));
  18.         }
  19.  
  20.  
  21.         public int OrderNum{get; set;}
  22.         public string CustName { get; set; }
  23.         public int QuantOrdered
  24.         {
  25.             get
  26.             {
  27.                 return quantOrdered;
  28.             }
  29.             set
  30.             {
  31.                 quantOrdered = value;
  32.                 totalPrice = Convert.ToInt32(quantOrdered) * Convert.ToInt32 (price);
  33.             }
  34.         }
  35.         public int TotalPrice
  36.         {
  37.             get
  38.             {
  39.                 return totalPrice;
  40.             }
  41.         }
  42.  
  43.            public static void Main()
  44.            {
  45.  
  46.                Order aOrder = new Order();
  47.                aOrder.OrderNum = 1;
  48.                aOrder.CustName = "Franklin, Benjamin";
  49.                aOrder.QuantOrdered = 6;
  50.                Console.WriteLine("Order information: {0}", aOrder);
  51.            }
  52.  
  53.  
  54.     }
  55. }
  56.  
The error message states: Error 1 'OrderDemo.Orde r' does not contain a constructor that takes '0' arguments
Sep 3 '10 #1
1 1507
Michael Tristan
2 New Member
I figured it out. I declared the parameters like this:
Expand|Select|Wrap|Line Numbers
  1.  public static void Main()
  2.            {
  3.  
  4.                Order aOrder = new Order(1, "Franklin, Benjamin", 6);
  5.                Order aOrder2 = new Order(2, "Jefferson, Thomas", 4);
  6.                Console.WriteLine("Order information:\n {0}\n{1}", aOrder, aOrder2);
  7.            }
  8.  
Sep 3 '10 #2

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

Similar topics

7
1666
by: hellwolf | last post by:
Hi,everyone.Because of my English level,I will try to use code to explain where I confused. //list of code: #include <iostream> #include <algorithm> #include <vector> class A{ static int si;
2
1604
by: indushekara | last post by:
Hi, I want to know what is the problem with this code. I am trying to insert in a map<int,A> where in i have defined the copy constructor for A I get the following error in VS6. e:\program files\microsoft visual studio\vc98\include\utility(21) : error C2558: class 'A' : no copy constructor available e:\program files\microsoft visual studio\vc98\include\utility(21) : while compiling class-template member function '__thiscall std::pair<int...
0
1675
by: John Haigh | last post by:
Should possibly have an "add" method in a PostingObject class in the constructor of PostingObject. will call to add a Posting to the ? Does this make sense? My sense is that a PostingObject needs a Posting, so would I do this in the PostingObject Constructor? Here is my code: using System; using System.Collections; using Microsoft.ContentManagement.Publishing;
2
1215
by: Daniel Groh | last post by:
Im my Application_Error i have a code that throw an error to my Email when any errors occurs, but the application is running normally and sometimes i get the following error in my Email address: Error Caught in Application_Error event Error in: http://localhost/LivrosOnline/get_aspx_ver.aspx Error Message:C:\Inetpub\wwwroot\LivrosOnline\get_aspx_ver.aspx Stack Trace: at System.Web.UI.TemplateParser.GetParserCacheItem() at...
2
1504
by: Joe Fallon | last post by:
I have a Shared class with a New constructor that initializes some Shared properties. One of the steps involves a hit to the database. My tests show that when called by a WinForms app, the constructor only runs once. All calls to the class after this do not casues the construtor to run again. This means it is a one time hit to the database to load these properties. 1. Can someone confirm this?
18
2813
by: Indian.croesus | last post by:
Hi, If I am right Endianness is CPU related. I do not know if the question is right in itself but if it is then how does C handle issues arising out of Endianness. I understand that if we pass structures using sockets across platforms, we need to take care of Endianness issues at the application level. But for example, for the code using bitwise AND to figure out if a number is odd or even, how does C know the LSB position?
1
1640
by: emadazizsuria | last post by:
I'm getting the following error: 'Questionnaire' does not contain a definition for 'ProcessList' Here Questionnaire.cs is a class file that defines a getter function ProcessList. public class Questionnaire { private ArrayList ImpProcesses; public Questionnaire() {
10
2412
by: JosephLee | last post by:
In Inside C++ object Model, Lippman said there are four cases in which compile will sythesize a default constructor to initialize the member variables if the constructor is absent: 1. there is a virtual function; 2. virtual inheritance; 3.base class with explicit default constructor;
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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,...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7330
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, 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...
0
5632
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();...
0
4155
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.