Solved

constructors

Posted on 1998-10-25
7
177 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
  • 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 50 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now