Mail Archives: djgpp/1999/10/29/15:22:17
From: | "Philip Bock" <bockfam AT icenter DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
References: | <zXPQ3.20115$5i5 DOT 770016 AT typhoon DOT mbnet DOT mb DOT ca>
|
Subject: | Re: I get an error, but don't see why...
|
Lines: | 178
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.00.2314.1300
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2314.1300
|
Message-ID: | <HZjS3.919$1J5.70589@typhoon.mbnet.mb.ca>
|
Date: | Fri, 29 Oct 1999 16:31:35 GMT
|
NNTP-Posting-Host: | 207.161.236.46
|
X-Trace: | typhoon.mbnet.mb.ca 941214695 207.161.236.46 (Fri, 29 Oct 1999 11:31:35 CDT)
|
NNTP-Posting-Date: | Fri, 29 Oct 1999 11:31:35 CDT
|
Organization: | MBnet Networking Inc.
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Fixed that error, and feel duly stupid. However, other more worthy errors
come to take that one's place. What I'm trying to do is create a vector
graphics renderer. So I have vector images stored as structs (called vimg),
with an array of pointers to the shapes that make up the vector drawings
(called shape). But it seems that the compiler doesn't go for the idea that
I want to designate an array in a struct without defining it's size, so I
tried just defining it as a pointer, trusting my constructor to deal with
the assignment. But when the constructor assigns the pointer a value that
points to another pointer (e.g. the beginning of the array) I get more error
messages. Not as cryptic as last time, but definitely non-helpful. How do I
fix?
Errors:
vector.cpp: In method `shape::shape(int, int, int)':
vector.cpp:139: assignment to `vector *' from `vector **'
vector.cpp: In method `vimg::vimg(int, int, int *)':
vector.cpp:147: assignment to `shape *' from `shape **'
vector.cpp:149: no match for `shape & = shape *'
vector.cpp:24: candidates are: struct shape & shape::operator =(const
shape&)
Code:
#include <allegro.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
struct coord
{
int x, y;
};
struct vector
{
coord c1, c2;
int color;
};
struct shape
{
int numvects;
int stype;
int sfill;
vector *vects;
shape(int newnumvects, int newstype, int newsfill);
};
struct vimg
{
int numvectors, numshapes;
vector *vectors;
shape *shapes;
vimg(int nnumv, int nnums, int vpers[]);
};
void program_init(void);
void draw_vimg(vimg vectimg);
vimg *gen_vimg(void);
shape::shape(int newnumvects, int newstype, int newsfill);
vimg::vimg(int nnumv, int nnums);
int main(void)
{
// program_init();
// set_gfx_mode(GFX_VESA1, 640, 480, 0, 0);
vimg *mygraphic;
mygraphic = gen_vimg();
// draw_vimg(mygraphic);
// set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
}
void program_init(void)
{
clrscr();
gotoxy(37, 1);
cout << "Atest1\n";
cout << "Initializing Allegro library...\n";
allegro_init();
cout << "Setting up timer...\n";
install_timer();
cout << "Initializing mouse routines...";
if (install_mouse() == -1)
cout << "failed\n";
else
cout << '\n';
cout << "Detected Operating System: ";
if (os_type == OSTYPE_UNKNOWN)
cout << "MS-DOS\n";
if (os_type == OSTYPE_WIN95)
cout << "Windows 95\n";
if (os_type == OSTYPE_DOSEMU)
cout << "Linux DOSEMU\n";
}
void draw_vimg(vimg vectimg, int x, int y, int xscale, int yscale)
{
for(int a = 0; a != vectimg.numshapes; a++)
{
//Code to draw one shape's outline
for(int b = 0; b != vectimg.shapes[a].numvects; b++)
line(screen, (vectimg.shapes[a].vects[b].c1.x*xscale)+x,
(vectimg.shapes[a].vects[b].c1.y*yscale)+y,
(vectimg.shapes[a].vects[b].c2.x*xscale)+x,
(vectimg.shapes[a].vects[b].c2.y*yscale)+y,
vectimg.shapes[a].vects[b].color);
// Code to fill shape goes here.
}
}
vimg *gen_vimg(void)
{
int vpers[]={6};
vimg newvimg(6, 1, vpers);
newvimg.vectors[0].c1.x = 50;
newvimg.vectors[0].c1.y = 1;
newvimg.vectors[0].c2.x = 100;
newvimg.vectors[0].c2.y = 1;
newvimg.vectors[0].color = 1;
newvimg.vectors[1].c1.x = 100;
newvimg.vectors[1].c1.y = 1;
newvimg.vectors[1].c2.x = 150;
newvimg.vectors[1].c2.y = 50;
newvimg.vectors[1].color = 1;
newvimg.vectors[2].c1.x = 150;
newvimg.vectors[2].c1.y = 50;
newvimg.vectors[2].c2.x = 100;
newvimg.vectors[2].c2.y = 100;
newvimg.vectors[2].color = 1;
newvimg.vectors[3].c1.x = 100;
newvimg.vectors[3].c1.y = 100;
newvimg.vectors[3].c2.x = 50;
newvimg.vectors[3].c2.y = 100;
newvimg.vectors[3].color = 1;
newvimg.vectors[4].c1.x = 50;
newvimg.vectors[4].c1.y = 100;
newvimg.vectors[4].c2.x = 1;
newvimg.vectors[4].c2.y = 50;
newvimg.vectors[4].color = 1;
newvimg.vectors[5].c1.x = 1;
newvimg.vectors[5].c1.y = 50;
newvimg.vectors[5].c2.x = 50;
newvimg.vectors[5].c2.y = 1;
newvimg.vectors[5].color = 1;
newvimg.shapes[0].vects[0] = newvimg.vectors[0];
newvimg.shapes[0].vects[1] = newvimg.vectors[1];
newvimg.shapes[0].vects[2] = newvimg.vectors[2];
newvimg.shapes[0].vects[3] = newvimg.vectors[3];
newvimg.shapes[0].vects[4] = newvimg.vectors[4];
newvimg.shapes[0].vects[5] = newvimg.vectors[5];
}
shape::shape(int newnumvects, int newstype, int newsfill)
{
numvects = newnumvects;
stype = newstype;
sfill = newsfill;
vects = new vector *[newnumvects];
}
vimg::vimg(int nnumv, int nnums, int vpers[])
{
numvectors = nnumv;
numshapes = nnums;
vectors = new vector [nnumv];
shapes = new shape *[nnums];
for (int c = 0; c != nnums; c++)
shapes[c] = new shape(vpers[c], 0, 0);
}
- Raw text -