whats this error??? help

This is a discussion on whats this error??? help within the C++ Programming forums, part of the General Programming Boards category; hi guys,,,can u plz tell me why i get the following error when i compile my 4 files????? i have ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    whats this error??? help

    hi guys,,,can u plz tell me why i get the following error when i compile my 4 files?????
    i have in my image.h file :


    #include <vector>
    #include "colour.h"
    #include <iostream>
    #include "canvas.h"


    class Image {
    public:
    Image( );
    ~Image();

    void draw_line(int x1, int y1, int x2, int y2);
    void draw_box(int x1, int y2, int x2, int y2);
    void draw_circle(int x, int y, int r);
    void draw_fill(int x, int y);
    };

    and my image.cc is :

    #include Image.h
    #include<iostream>
    #include<cmath>
    #include <algorithm>

    void draw_line(int x1, int y1, int x2, int y2) {
    int dx = x2-x1;
    int dy = y2-y1;

    set_pixel(x1,y1);
    if (std::abs(dx) > std::abs(dy)) {
    double m = static_cast<double>(dy) / static_cast<double>(dx);
    double b = y1 - m*x1;
    dx = (dx < 0) ? -1 : 1;
    while (x1 != x2) {
    x1+=dx;
    set_pixel(x1,static_cast<int>(std::floor(m*x1+b+0. 5)));
    }
    } else {
    double m = static_cast<double>(dx) / static_cast<double>(dy);
    double b = x1 - m*y1;
    dy = (dy < 0) ? -1 : 1;
    while (y1 != y2) {
    y1+=dy;
    set_pixel(static_cast<int>(std::floor(m*y1+b+0.5)) ,y1);
    }
    }
    }



    void draw_box(int x1, int y1, int x2, int y2) {
    if (x1>x2)
    std::swap(x1,x2);
    if (y1>y2)
    std::swap(y1,y2);
    if (x1==x2 || y1==y2)
    draw_line(x1,y1,x2,y2);
    else if (x1+1 == x2) {
    draw_line(x1,y1,x1,y2);
    draw_line(x2,y1,x2,y2);
    } else if (y1+1 == y2) {
    draw_line(x1,y1,x2,y1);
    draw_line(x1,y2,x2,y2);
    } else {
    draw_line(x1,y1,x1,y2);
    draw_line(x2,y1,x2,y2);
    draw_line(x1+1,y2,x2-1,y2);
    draw_line(x1+1,y1,x2-1,y1);
    }
    }

    void draw_circle(int x, int y, int r) {
    set_pixel(x,y+r);
    set_pixel(x,y-r);
    set_pixel(x+r,y);
    set_pixel(x-r,y);

    int r2 = r*r;
    int xp = 1;
    int yp = static_cast<int>(std::sqrt(static_cast<double>(r2-1))+0.5);
    while (xp < yp) {
    set_pixel(x + xp, y + yp);
    set_pixel(x + xp, y - yp);
    set_pixel(x - xp, y + yp);
    set_pixel(x - xp, y - yp);
    set_pixel(x + yp, y + xp);
    set_pixel(x + yp, y - xp);
    set_pixel(x - yp, y + xp);
    set_pixel(x - yp, y - xp);
    xp++;
    yp = static_cast<int>(std::sqrt(static_cast<double>(r2-xp*xp)) +0.5)
    }
    if (xp == yp) {
    set_pixel(x + xp, y + yp);
    set_pixel(x + xp, y - yp);
    set_pixel(x - xp, y + yp);
    set_pixel(x - xp, y - yp);
    }
    }

    void draw_fill(int x, int y) {
    if ( x <0 || x >= get_width() || y<0 || y>=get_height())
    return;
    if (get_pixel(x,y) != get_colour()) {
    set_pixel(x,y);
    draw_fill(x-1,y);
    draw_fill(x+1,y);
    draw_fill(x,y+1);
    draw_fill(x,y-1);
    }
    }


    the command class.h is:

    #ifndef COMMAND_H
    #define COMMAND_H

    bool parse_command(std::istream &is);

    #endif


    and the command.cc is:

    #include <string>
    #include <iostream>

    #include "Image.h"

    static bool size_done = false;

    static bool cmd_size(std::istream &is) {
    int x,y;
    is >> x >> y;
    if (! is)
    return false;
    if (size_done)
    return false;
    size_done = true;
    set_size(x,y);
    return true;
    }
    static bool cmd_colour(std::istream &is) {
    std::string col;
    is >> col;
    if (col == "black")
    set_colour(BLACK);
    else if (col == "white")
    set_colour(WHITE);
    else if (col == "xor")
    set_colour(XOR);
    else
    return false;
    return true;
    }

    static bool cmd_point(std::istream &is) {
    int x,y;
    is >> x >> y;
    if (! is)
    return false;
    set_pixel(x,y);
    return true;
    }

    static bool cmd_line(std::istream &is) {
    int x1, y1, x2, y2;
    is >> x1 >> y1 >> x2 >> y2;
    if (! is)
    return false;
    draw_line(x1,y1,x2,y2);
    return true;
    }

    static bool cmd_box(std::istream &is) {
    int x1,y1,x2,y2;
    is >> x1 >> y1 >> x2 >> y2;
    if (! is)
    return false;
    draw_box(x1,y1,x2,y2);
    return true;
    }

    static bool cmd_circle(std::istream &is) {
    int x,y,r;
    is >> x >> y >> r;
    if (! is)
    return false;
    draw_circle(x,y,r);
    return true;
    }

    static bool cmd_fill(std::istream &is) {
    int x,y;
    is >> x >> y;
    if (! is)
    return false;
    if (get_colour() == XOR)
    return false;
    draw_fill(x,y);
    return true;
    }

    bool parse_command(std::istream &is) {
    std::string cmd;
    is >> cmd;
    if (! is)
    return false;
    if (cmd == "size")
    return cmd_size(is);

    if (!size_done)
    return false;

    if (cmd == "colour")
    return cmd_colour(is);
    else if (cmd == "point")
    return cmd_point(is);
    else if (cmd == "line")
    return cmd_line(is);
    else if (cmd == "box")
    return cmd_box(is);
    else if (cmd == "circle")
    return cmd_circle(is);
    else if (cmd == "fill")
    return cmd_fill(is);

    return false;
    }

    sorry for the long post,,,i dont have anyone to help me out and i cant figure out what it is that i am doing wrong,,,,all the header files seem right to me,,,dont they?

    canvas and main compile ok!
    any ideas guys???? i am stuck

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    10
    i actually forgot to give you the error,,,oops
    here it is:
    when i compile like so:
    $ g++ -o main main.cc Image.cc canvas.cc command.cc
    i get:

    command.cc: In function `bool cmd_line(istream &)':
    command.cc:48: implicit declaration of function `int draw_line(...)'
    command.cc: In function `bool cmd_box(istream &)':
    command.cc:57: implicit declaration of function `int draw_box(...)'
    command.cc: In function `bool cmd_circle(istream &)':
    command.cc:66: implicit declaration of function `int draw_circle(...)'
    command.cc: In function `bool cmd_fill(istream &)':
    command.cc:77: implicit declaration of function `int draw_fill(...)'

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, in your .cc files, to define a member function of the class, you must give it the class scope beforehand.

    So, change things like:
    Code:
    void draw_line(int x1, int y1, int x2, int y2) {
    	int dx = x2-x1;
    	int dy = y2-y1;
    .
    .
    .
    etc.
    to
    Code:
    void Image::draw_line(int x1, int y1, int x2, int y2) {
    int dx = x2-x1;
    int dy = y2-y1;
    .
    .
    .
    etc.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Unhappy done but still

    I did wha tyou suggested V and its still gives me the exact same errors?????
    any other ideas?????
    and here is my canvas class if thats going to be any help,,,,i am spending hours on it and zilch ,,,no idea comes to mind,,,any feedback would be great


    #ifndef CANVAS_H
    #define CANVAS_H
    #include "colour.h"
    #include <iostream>

    void set_size(int x, int y);
    void set_colour(colour c);

    int get_height();
    int get_width();
    colour get_colour();

    void set_pixel(int x, int y);
    bool get_pixel(int x ,int y);
    void output_image(std:stream &os);

    #endif



    and canvas.cc
    #include "canvas.h"

    #include <vector>

    static std::vector<bool> canvas;
    static int height;
    static int width;
    static colour col;

    void set_pixel(int x, int y) {
    if (x<0 || y<0 || x>=width || y>=height)
    return; //don't plot out of range pixels
    if (col==XOR)
    canvas[y*width+x] = !canvas[y*width+x];
    else
    canvas[y*width+x] = (col==BLACK);
    }

    bool get_pixel(int x, int y) {
    if (x<0 || y < 0 || x>=width || y>=height)
    return false;
    else
    return canvas[y*width+x];
    }

    int get_height() {
    return height;
    }

    int get_width() {
    return width;
    }

    void set_size(int x, int y) {
    if (width || height)
    return;
    canvas.resize(x*y,false);
    width = x;
    height = y;
    }

    void set_colour(colour c) {
    col = c;
    }

    colour get_colour() {
    return col;
    }

    void output_image(std:stream &os) {
    os << "P1\n" << width << ' ' << height << '\n';
    for(std::vector<bool>::const_iterator b=canvas.begin(), e=canvas.end();
    b!=e ; ++b)
    os << *b << '\n';
    }

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Smile

    dont worry about it,,got it!!!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21