Solved

constructors

Posted on 1998-10-25
7
180 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 158
C language IDE – Compilers installation 14 75
Would like to move button in a function 3 79
White board coding practice 3 92
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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

821 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