Results 1 to 10 of 10

Thread: Why C++ doesn't allow this?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    Question Why C++ doesn't allow this?

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    class fourpoint
    {
       public:
       int w,x,y,z;
    
    
       fourpoint();
       fourpoint(int w,int x,int y,int z);
       ~fourpoint();
    
    
    
    
    } ;
    fourpoint::fourpoint()
    {
    
    }
    fourpoint::fourpoint(int w=0,int x=0,int y=0,int z=0)
    {
        this->w=w;
        this->x=x;
        this->y=y;
        this->z=z;
    
    
    }
    
    fourpoint::~fourpoint()
    {
    
    
    }
    
    
    
    int main()
    {
    
          fourpoint *sh= new fourpoint(40,40);
          cout<<endl<< sh->w <<" "<< sh->x;
          cout<< " "<< sh->y <<" "<< sh->z<<endl<<endl;
          system("PAUSE");
          return 0;
    }
    I can't do this

    fourpoint *sh= new fourpoint( , ,40,40);//error

    Looks like not very flexible to me as it allows no parameters for the back but it needs you to put parameters in front even though the value of front parameters is default.

    p.s. the above program doesn't do anything useful, it was written by me to test whether no front parameters works or not.
    Last edited by transcendental; Jan 2nd, 2002 at 08:03 PM.
    I'm a VB6 beginner.

  2. #2
    Addicted Member
    Join Date
    Aug 2001
    Location
    I'm mobile
    Posts
    166
    Maybe it takes the " , , "as non defined values at all and return errors therefore......?
    [p r a e t o r i a n]

  3. #3
    I think optional arguments have to be the last arguments for this very reason. VB actually did somethinge better than C++!

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Hehe, don't you know it. I think C++ is expecting something like praetorian said, so that you're getting an error. VB did do something right after all!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You can do some tricks with templates and overloading, but the syntax will be a bit different.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Addicted Member
    Join Date
    Aug 2001
    Location
    I'm mobile
    Posts
    166
    Kedaman,
    do you have any examples of that?
    [p r a e t o r i a n]

  7. #7
    Addicted Member goudabuddha's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere cheesy
    Posts
    203
    Originally posted by filburt1
    I think optional arguments have to be the last arguments for this very reason. VB actually did somethinge better than C++!
    Finally!!

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yes, but C++ is considerably, considerably, faster than VB
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    I am not sure...

    but i think all you have to do to overload the constructor function is to create another prototype...

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    my Bork expression templates does this for example, but it's not quite simple, besides it requires typing everything.

    To pass two same datatypes in a specific order you need overloaded functions, and to distinguish the order your parameterize it. Another way would be to force typing for parameters, which is what Bork is doing.

    Btw, it's trickier if you use MSVC, since it has to deduce what parameters are used for the overloaded functions, but you can force to use explicit <> parameterisation if you make a default value for a parameter passed, it's not ANSI compliant but that's MSVC for you
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width