|
-
Jan 2nd, 2002, 07:52 PM
#1
Thread Starter
Hyperactive Member
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.
-
Jan 2nd, 2002, 08:06 PM
#2
Addicted Member
Maybe it takes the " , , "as non defined values at all and return errors therefore......?
-
Jan 2nd, 2002, 08:31 PM
#3
Member
I think optional arguments have to be the last arguments for this very reason. VB actually did somethinge better than C++!
-
Jan 2nd, 2002, 08:46 PM
#4
Good Ol' Platypus
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)
-
Jan 3rd, 2002, 01:43 AM
#5
transcendental analytic
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.
-
Jan 3rd, 2002, 07:09 AM
#6
Addicted Member
Kedaman,
do you have any examples of that?
-
Jan 3rd, 2002, 08:30 AM
#7
Addicted Member
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!!
-
Jan 3rd, 2002, 02:20 PM
#8
Monday Morning Lunatic
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
-
Jan 3rd, 2002, 10:25 PM
#9
Lively Member
I am not sure...
but i think all you have to do to overload the constructor function is to create another prototype...
-
Jan 5th, 2002, 12:54 PM
#10
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|