Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

constructors

Posted on 1998-10-25
7
Medium Priority
?
183 Views
Last Modified: 2010-04-02
I have a class:
class number
{
   public:
   number(int one=0,int two=1){num1=one;num2=two;}

   private:
   int num1;
   int num2;
};
  in the constructor above I am trying to get two to default
  to 1 and if it is sent a 0 cahgee it to a 1.
Thanks for the halp in advance.
   
0
Comment
Question by:strmtrpr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 

Expert Comment

by:jbalagop
ID: 1176059
I have a class:
class number
{
   public:
   number(int one=0,int two=1){
           num1=one;
           if(two = 0)
              num2 = 1;
           else
              num2=two;
   }

   private:
   int num1;
   int num2;
};

Is that what you want to do?
0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1176060
I'm not sure I understand.  Do you just mean?

class number
   {
      public:
      number(int one=0,int two=1)
     {
         num1=one;
         if (two == 0)
            two = 1;
         num2=two;
     }

      private:
      int num1;
      int num2;
   };


let me know if you have questions.
0
 

Expert Comment

by:jbalagop
ID: 1176061
in the code above : if(two = 0) is actually if(two == 0), but you already knew that.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 22

Expert Comment

by:nietod
ID: 1176062
Looks like jbalagop beat me to it.  I guess that is what you wanted, his thought was the same as mine.  He was slightly faster, so you might want to reject my answer so he can answer.
0
 

Author Comment

by:strmtrpr
ID: 1176063
I forgot the ==  with one equal sign I was just assinging 0 to two, right?
Thanks for all your help

0
 
LVL 22

Expert Comment

by:nietod
ID: 1176064
Yes, a single = assigns and a double == compares.  
0
 

Author Comment

by:strmtrpr
ID: 1176065
I am slowly starting to get the hang of this I think.
I wanted to thank everyone who answers my questions so quickly.

Thanks again.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question