Hi, I am using Visual Studio 2008 and I am writing an MFC Dialog Based Application.
I have two trobules - the program uses brushes to draw the lines throw the points from the CPoint table - but the density of points may be vary every time. So my idea was to start in class the table with 10 points and expand the table every 10 next points, the expanding code looks so:

if (which_move1 % 10 == 0) {
		CPoint *temp;
		temp = new CPoint[which_move1 + 10];
		for (int i = 0; i < which_move1; i++) {
			temp[i] = way1[i];
		}
		way1 = temp;

		temp = new CPoint[which_move2 + 10];
		for (int i = 0; i < which_move2; i++) {
			temp[i] = way2[i];
		}
		way2 = temp;
		
	}
	else;

And I am getting the error C2440: '=' : cannot convert from 'CPoint *' to 'CPoint [10]'

The program uses first 4 point on OnPaint function, which works before OnInitDialog so I need to start with created table.

----------------------

The second problem is - in the program I have 2 dialogs with two seperate classes. First class defines object z, and the second y. First I am writing data to this CPoint table at first class, then opens the second dialog with question if user wants to save those points. How to get access to the object z from second class?

> way1 = temp;
Edward will guess that way1 is declared as

CPoint way1[10];

Arrays in C++ are almost-but-not-quite first class types because they do not allow assignment. To copy items from one array to another, or from a dynamic array to a static array, each element must be copied individually.

It looks like you want to increase the size of way1 and way2, but if they really are static arrays, the size cannot be changed. Have you considered the C++ vector class? :)

> How to get access to the object z from second class?
Write a public accessor in the first class, or give the second class friend access. Ed recommends the public accessor because it limits the failure points in how the second class can monkey with the first class.

Yeah... sorry, I forget to write the declaration. It is exactly as you typed.
I have an idea to copy points from way1 to temp, delete way1, create new way1 expanded and copy points back from temp inside it.

Avout getting access - I think that I will use friend, I don't have any experience with accessors and any idea for it.

Thx

> I have an idea to copy points from way1 to temp, delete way1, create new way1 expanded and copy points back from temp inside it.
That works if way1 is also a dynamic array like temp, but if way1 is an array like you say, the size is static and cannot change. Managing dynamic arrays is tedious, you really should consider the C++ vector class instead. It grows and shrinks dynamically without making you manage memory and pointers. :)

> Avout getting access - I think that I will use friend, I don't have any experience with accessors and any idea for it.
Sho' nuff. For future reference, an accessor is just a public method that returns the object.

class Foo {
    int x;
public:
    // I'm a get accessor
    int get_x() { return x; }

    // I'm a set accessor
    void set_x(int value) { x = value; }
};

If you make the second class a friend, it means that any method in the second class can access the first class' private and protected data. Probably not a problem right now. Ed assumes that any questions on Daniweb are from students rather than pros, but it is important in pro code to guarantee the state of an object at any given time.

Maintaining a clean state gets harder to do when there are more places where unrestricted access is possible. After all, if there are too many fingers in the cookie dough, the cookies start to taste funny. The solution is to keep wandering fingers out of the kitchen. ;)

Thx man very much. I appreciate your tips. I am student and very beginner of programming world, but soon I want be a really good coder, so such tips are very helpful to write good programs.

I'll try this now.

This article has been dead for over six months. Start a new discussion instead.