CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Is a default constructor with default values is parametric or nonparametric ?

  1. #1

    Is a default constructor with default values is parametric or nonparametric ?

    class A defines default constructor with default values.

    I) Is it default or parameterised constructor?

    My opinion is that it is parametric when it is called with values like A a1(x1,y1) and it is default when it is called like A a2()? Pl suggest.


    Code:
    class A
    {
    int a;
    int b;
    
    public:
    
    A(int x=10,int y=20)
    {
    
    }
    };
    Last edited by forumuser11@gmail.com; August 23rd, 2010 at 04:55 AM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Is a default constructor with default values is parametric or nonparametric ?

    Quote Originally Posted by forumuser11@gmail.com View Post
    class A defines default constructor with default values.

    I) Is it parametric or non-parametric?
    I have never heard of these terms used before in the context of your question. Parametric? non-Parametric? What is that supposed to mean? A default constructor can have arguments if all the arguments are defaulted. Basically, a default constructor is a constructor that is able to construct an object with no arguments given. Any other explanation further than that is fluff.
    My opinion is that it is parametric when it is called with values like A a1(x1,y1)
    You called it with parameters. Whatever "parametric" is supposed to mean, I don't know.
    and it is non-parametric when it is called like A a2()?
    First of all, this:
    Code:
    A a2();
    does not construct an object. What it does is declare a function called a2() that takes no arguments, and returns an A object.

    What you mean is this:
    Code:
    A a2;
    As far as non-Parametric, you constructed an A with no parameters, therefore you called the default constructor.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; August 23rd, 2010 at 04:09 AM.

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Is a default constructor with default values is parametric or nonparametric ?

    The only use of the word parametric I have ever seen is combined with polymorphism: "parametric polymorphism", which is basically a very strange (and confusing in a C++ context) way to say "template".

    You'd better ask your teacher to be more clear about his question, or review your class material. Or change class.
    Last edited by monarch_dodra; August 23rd, 2010 at 04:03 AM.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #4
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Is a default constructor with default values is parametric or nonparametric ?

    "parametric" is a mathematical term, I've never heard it in computer science outside of that context. In math, a parametric equation is an equation that shows a relationship between two variables.

  5. #5
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Is a default constructor with default values is parametric or nonparametric ?

    Maybe "Default optionally-parameterised constructor" will be OK for your teacher...

  6. #6
    Join Date
    Aug 2010
    Posts
    77

    Re: Is a default constructor with default values is parametric or nonparametric ?

    Parametric polymorphism is the counterpart to ad hoc polymorphism. The former describes generic behavior independent of the type of the object or objects, the latter the distinct behavior dependent of different type of the object or objects. "template" is just a C++ term for compile time polymorphism, usually which is parametric but not necessarily (specializations are ad hoc) as well as parametric classes and their counterpart(ad hoc classes?)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)