-5

I have this void function in c++

void DrawFace(cv::Mat img, Window face)
{
    int x1 = face.x;
    int y1 = face.y;
    int x2 = face.width + face.x - 1;
    int y2 = face.width + face.y - 1;
    int centerX = (x1 + x2) / 2;
    int centerY = (y1 + y2) / 2;
    std::vector<cv::Point> pointList;
    pointList.push_back(RotatePoint(x1, y1, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x1, y2, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x2, y2, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x2, y1, centerX, centerY, face.angle));
    DrawLine(img, pointList);
}

i wanted this to return me just the pointList vector for which i made this change

void Drawface(cv::Mat img, Window face) 
{
    int x1 = face.x;
    int y1 = face.y;
    int x2 = face.width + face.x - 1;
    int y2 = face.width + face.y - 1;
    int centerX = (x1 + x2) / 2;
    int centerY = (y1 + y2) / 2;
    std::vector<cv::Point> pointList;
    pointList.push_back(RotatePoint(x1, y1, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x1, y2, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x2, y2, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x2, y1, centerX, centerY, face.angle));
    return pointList
}

It would be really helpful if somebody could point out where i have gone wrong and what changes i could make.

Thanks in advance

Ryan
  • 8,459
  • 14
  • 40
  • 66
  • 2
    Change the signature of the function to `std::vector Drawface(cv::Mat img, Window face)`. – Ted Lyngmo Dec 20 '18 at 12:32
  • https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Biffen Dec 20 '18 at 12:32
  • @Ryan Great! Note that this is exactly the same as Vittorio suggests in his answer if you read it closely ("_....return type is still `void`. You need to change it to reflect the changes in the body_"). – Ted Lyngmo Dec 20 '18 at 12:50
  • Easy alternative - change declaration "void Drawface(cv::Mat img, Window face)" and add a reference pointList to the parameter list: "void Drawface(cv::Mat img, Window face, std::vector& pointList)" – 2785528 Dec 21 '18 at 18:34

2 Answers2

5

Your function's return type is still void. You need to change it to reflect the changes in the body. Also, missing a semicolon after return pointList.

Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
  • Hi ,Thanks , i have added the semicolon, i have also removed the void.Now it looks like `Drawface(cv::Mat img, Window face)` ,is this okay? – Ryan Dec 20 '18 at 12:31
  • 3
    No. You obviously need to read a beginner C++ book. StackOverflow is not the right place to help you with the basics such as function signatures. See: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Vittorio Romeo Dec 20 '18 at 12:32
  • Okay ,cool .Thanks for the help though ,ill look into it. – Ryan Dec 20 '18 at 12:32
4

You need to declare the return type of the function.

std::vector<cv::Point> Drawface(cv::Mat img, Window face) 
{
    int x1 = face.x;
    int y1 = face.y;
    int x2 = face.width + face.x - 1;
    int y2 = face.width + face.y - 1;
    int centerX = (x1 + x2) / 2;
    int centerY = (y1 + y2) / 2;
    std::vector<cv::Point> pointList;
    pointList.push_back(RotatePoint(x1, y1, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x1, y2, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x2, y2, centerX, centerY, face.angle));
    pointList.push_back(RotatePoint(x2, y1, centerX, centerY, face.angle));
    return pointList;
}
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217