| |

VerySource

 Forgot password?
 Register
Search
View: 813|Reply: 8

Solve the problem of class definition and linked list class

[Copy link]

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-7 17:30:01
| Show all posts |Read mode
I want to compile a drawing program, which uses a variety of graphic elements (line, rectangle, circle, etc.), each graphic element must create a class (derived from a self-created graphic class), but when using a linked list class What should I do when storing these graphics? Or how to create this linked list class? What should its data type be? Use CList or CObList?
Thank you,
Reply

Use magic Report

1

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-12-7 17:45:01
| Show all posts
class CElement
{
public:
virtual void Draw(){};
};

class CLine: public CElement {};
class CCircle: public CElement {};

std::vector< CElement*> myList;
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-12-7 20:00:01
| Show all posts
CObList requires that your graphics class must be inherited from MFC's CObject, so it may be better to use the template class CList<...>
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-7 20:30:01
| Show all posts
First, you must define a few points, for example, the first node, pointer, and end node.
Store these points again to save the line information
Reply

Use magic Report

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-12-7 20:45:01
| Show all posts
Thank you, the big brothers upstairs.
If I want to create only a linked list class to store various graphic elements, what is the data element type of my linked list class? Can I use a base class? Do I have to use pointers?
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-12-7 21:00:01
| Show all posts
Use base class pointers or references, not base class objects
Reply

Use magic Report

0

Threads

55

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-12-7 21:15:01
| Show all posts
// Point3D.h: interface for the CPoint3D class.
//
////////////////////////////////////////////////// ////////////////////
#include <afxtempl.h>

#if !defined(AFX_POINT3D_H__FB60210D_9230_43D0_B3C5_1FA12314F579__INCLUDED_)
#define AFX_POINT3D_H__FB60210D_9230_43D0_B3C5_1FA12314F579__INCLUDED_

#if _MSC_VER> 1000
#pragma once
#endif // _MSC_VER> 1000

#define LIMITVALUE 0.0001 //×ø±êÏàµÈÏÞÖµ 2014.2.25. ËÕ¼Ó¡ £


//Èýά¿ Õ¼äµã×ø±êÀà

class CPoint3D
{
public:
CPoint3D();
CPoint3D(double x);
CPoint3D(double x,double y);
CPoint3D(double x,double y,double z);
virtual ~CPoint3D();

public:
double x;
double y;
double z;

void Maximal(CPoint3D&p);
void Minimal(CPoint3D&p);
void Maximal(double * p);
void Minimal(double * p);
virtual CPoint3D operator= (const CPoint3D&p);
virtual CPoint3D operator+ (const CPoint3D&p);
virtual CPoint3D operator- (const CPoint3D&p);
virtual CPoint3D operator* (const CPoint3D&p);
// 2014.2.25. Ëոġ £
virtual bool operator==(const CPoint3D&p);
virtual CPoint3D operator*=(const double scale);
virtual CPoint3D operator+=(const CPoint3D&p);
virtual CPoint3D operator-=(const CPoint3D&p);
virtual CPoint3D operator= (const double * p);
};

//´øÓÐÊôÐÔÂëά×ø±êµãÀà

class CCodePoint3D: public CPoint3D
{
public:
CCodePoint3D();
virtual ~CCodePoint3D();

public:
long code;

public:
virtual CCodePoint3D operator = (const CCodePoint3D&p);
CCodePoint3D *Create(long Code);
CCodePoint3D *Create(long Code,double x,double y,double z);
};

typedef CArray<CPoint3D,CPoint3D> CPoint3DArray;
typedef CArray<CCodePoint3D,CCodePoint3D> CCodePoint3DArray;
typedef struct
{
long lNo;
CPoint3DArray Point3DArray;
}POINT3DARRAY;
typedef CTypedPtrList<CPtrList, POINT3DARRAY*> CPoint3DArrayList;

#endif // !defined(AFX_POINT3D_H__FB60210D_9230_43D0_B3C5_1FA12314F579__INCLUDED_)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-12-8 17:15:01
| Show all posts
Inherit CObject, store it in CList, just use the base class pointer, the example given upstairs is very good, generally write according to this idea.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-8 17:30:01
| Show all posts
Refer to Microsoft's vector drawing program drawcli. In the above example, you have learned that this is not a problem.
No matter what the linked list is, it can achieve the purpose.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list