| msdagiya (26) | |||
After calling class Point inside class Triangle I get this error. no matching function for call to Point::Point(). Does any one know if there is anything wrong with my code. Please help. -Sumair | |||
|
|
|||
| Peter87 (3691) | |||
|
You can't call a class. You can create instances of a class and call its member functions. Since you have not specified which constructor to be used to initialize the objects in P it will try to use the default constructor (constructor that takes no arguments). Point doesn't have a default constructor so that's what the error message "no matching function for call to Point::Point()" is about. Either create a default constructor or specify the constructor in the constructor initialization list.
To make line 26-28 compile you would have to define operator(int, int) as a member of Point. | |||
|
Last edited on
|
|||
| msdagiya (26) | |
| Can you write the code of defining the operator(int,int). I don't understand why we need this. | |
|
|
|
| Peter87 (3691) | |
| You don't need it. I was just saying that if you wanted that exact syntax to compile you would have to. | |
|
|
|
| msdagiya (26) | |
|
After I added the default point constructor I get a new error; "no match for call to (Point)(int,int)" | |
|
|
|
| vlad from moscow (3112) | |||
This code
is invalid. Expression for example, P[0](0,0); means calling of the function call operator that was not defined in class Point. | |||
|
|
|||
| msdagiya (26) | |||||
I learned in my C++ course that I can define a constructor like so
and then I can create an object like so inside main function:
Is this not the correct method of using constructor? because that what I am doing in the Triangle constructor. Initializing the Point in the Triangle constructor. | |||||
|
|
|||||