Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

constructors

Posted on 1998-10-25
7
Medium Priority
?
184 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 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's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

963 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