The simplest way is returning the object by value, the compiler optimizes that (NRVO).
Try
#include <iostream>
using namespace std;
struct Point
{
int x, y;
};
struct Triangle
{
Point p1,p2,p3;
Triangle(){cout << "Triangle ctor" << endl;}
};
Triangle makeTrianglePointingDown(int x, int y)
{
const int halfSize = 5;
Triangle t;
t.p1.x = x-halfSize;
t.p1.y = y-halfSize-halfSize;
t.p2.x = x+halfSize;
t.p2.y = y-halfSize-halfSize;
t.p3.x = x;
t.p3.y = y-2;
return t;
}
int main()
{
Triangle tpd = makeTrianglePointingDown(10,10);
cout << tpd.p1.x << " " << tpd.p1.y << " ";
cout << tpd.p2.x << " " << tpd.p2.y << " ";
cout << tpd.p3.x << " " << tpd.p3.y << endl;
}