-4

I have a method Close() in a class called X. I want to use that function in some other class called Y. I have created an object for class A and I call that Close() function there. At that time I am getting an error "No Appropriate default constructor Available."

I have created it like this..

X x;  x.Close();

How can I solve this?

Prabhu Harin
  • 69
  • 2
  • 7
  • 4
    [Post your code, please](http://stackoverflow.com/help/mcve) – Anton Savin Dec 10 '14 at 13:50
  • 4
    The error message is self-explanatory. The class doesn't have a default constructor and you're trying to use it. Either write one, or use a constructor with parameters. – Borgleader Dec 10 '14 at 13:52
  • 3
    I don't see how `class A` is relevant here. Could you elaborate please? – Bathsheba Dec 10 '14 at 13:52
  • 1
    @Borgleader The error is only self-explanatory is you understand what a default constructor is and why it needs to be available. If they had understood the error, they wouldn't be asking the question. – Joseph Mansfield Dec 10 '14 at 13:57
  • possible duplicate of [C++ - No appropriate default constructor available](http://stackoverflow.com/questions/19233174/c-no-appropriate-default-constructor-available) – Borgleader Dec 10 '14 at 14:02
  • oops..instead of class X, I said A..the code looks like x is the object for X class.. X x; x.close(); – Prabhu Harin Dec 10 '14 at 14:05
  • Why do you create an object only to call it's `close` function? It sounds like `close` should be a free function. – molbdnilo Dec 10 '14 at 14:11

1 Answers1

1

Either class X has no acceptable default constructor os some type used within method Close of class X has no default constructor.:) Either you should define the default constructor or use a constructor with parameters that is defined for the class.

I have a method Close() in a class called X. ... I have created an object for class A and I call that Close()

Also you need to put the place in order what is class X and what is class A.:)

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335