Hi friends, how can I get a reference to the center of AcGeCircArc2d. Am I approaching this incorrectly? Maybe I need to call geCir1.center() everytime?
static void Test() {
AcGeCircArc2d geCir1(AcGePoint2d(1, 1), 5);
AcGePoint2d &geCtr1 = geCir1.center();
acutPrintf(_T("\ngeCir1 Center is x: %f\ty: %f"), geCir1.center().x, geCir1.center().y);
acutPrintf(_T("\ngeCtr1 Center is x: %f\ty: %f"), geCtr1.x, geCtr1.y);
geCir1.setCenter(AcGePoint2d(5, 6));
acutPrintf(_T("\ngeCir1 Center is x: %f\ty: %f"), geCir1.center().x, geCir1.center().y);
acutPrintf(_T("\ngeCtr1 Center is x: %f\ty: %f"), geCtr1.x, geCtr1.y);
}
Output:
geCir1 Center is x: 1.000000 y: 1.000000
geCtr1 Center is x: 1.000000 y: 1.000000
geCir1 Center is x: 5.000000 y: 6.000000
geCtr1 Center is x: 1.000000 y: 1.000000
Thanks in advance for your time.
Solved! Go to Solution.
Solved by tbrammer. Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Solved by zrobert. Go to Solution.
Hi;
I may be completely wrong (I'm not a c ++ expert) but in a hurry, I think the reason is that the center () method is not declared as a reference type, but as a constant value type of AcGePoint2d. (GE_DLLEXPIMPORT AcGePoint2d center () const;). So, I think you have to call geCir1.center () all the way.
@karl.sch1983 wrote:
...Maybe I need to call geCir1.center() everytime?
Yes of course, as far as you using reference to method and not to variable.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
AcGeCircArc2d geCir1(AcGePoint2d(1, 1), 5);
AcGePoint2d& geCtr1 = geCir1.center(); //NO!!
AcGePoint2d geCtr2 = geCir1.center(); //ok.
If you would use the /permissive compiler option your code wouldn't even compile! You would get this error:
error C2440: "Initialisierung": Can't convert "AcGePoint2d" to "AcGePoint2d &"
It is misleading and may cause crashes to initialize a reference with an object that was retured from a function.
The reference AcGePoint2d &geCtr1 does NOT point to the centerpoint of geCir1, but to a temporary copy of it. When this temporary object goes out of scope, the reference becomes invalid.
Thanks @Alexander.Rivilis and @tbrammer it makes sense now. I didn't realize I was assigning a reference to a function. In my head I was thinking of it as a property of some primitive type which it clearly is not.
Thanks @zrobert for the link. It helps too.
Can't find what you're looking for? Ask the community or share your knowledge.