ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reference to AcGeCircArc2d

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
karl.sch1983
599 Views, 5 Replies

Reference to AcGeCircArc2d

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.

 

5 REPLIES 5
Message 2 of 6
zrobert
in reply to: karl.sch1983

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.

Message 3 of 6
zrobert
in reply to: karl.sch1983

Here is an example of declaring and defining a reference-type function, which would behave as you would like.

Example 

Message 4 of 6


@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
Expert Elite Member

Message 5 of 6
tbrammer
in reply to: karl.sch1983

	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.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 6 of 6

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.

Post to forums  

Forma Design Contest


AutoCAD Beta