473,503 Members | 11,281 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.Order' does not contain a constructor that takes '0' arguments
Sep 3 '10 #1
1 1501
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
1656
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...
2
1599
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...
0
1662
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...
2
1210
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: ...
2
1499
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...
18
2800
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...
1
1636
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...
10
2396
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...
0
7207
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
7095
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
7294
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
7470
tracyyun
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...
0
5602
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
4693
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
3183
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
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
403
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...

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.