Thread: Beginner's Problem With First Funtion

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    Unhappy Beginner's Problem With First Funtion

    Hi, I'm working through the You Can Do It! book by Francis Glassborow and am stuck on the chapter that introduces functions. Can anyone tell me why this won't build?
    Code:
    #include <iostream>
    #include "playpen.h"
    #include "drawing_functions.h"
    
    using namespace fgw;
    using namespace std;
    
    int main(){
     playpen paper;
     paper.scale(3);
     draw_a_cross(paper,-4,0,9,0,-4,9,black);
     paper.display();
     cout << "press return to end";
     cin.get();
     }
    The drawing functions header I made and it contains:
    Code:
    #ifdef DRAWING_FUNCTIONS_H
    #define DRAWING_FUNCTIONS_H
    
    #include "playpen.h"
    
    void draw_a_cross(fgw::playpen &,
     int left_of_cross_piece_x, int left_of_cross_piece_y,
     int width_of_cross,
     int bottom_of_cross_piece_x, int bottom_of_cross_piece_y,
     int height_of_cross,
     fgw::hue);
    
    #endif
    The playpen header makes all the paper and fgw stuff work fine. The IDE I'm using is Quincy. These are the errors I'm getting:
    http://www.picvault.info/images/5370...ildproblem.bmp

    Any help would be greatly appreciated.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    playpen.h must include a prototype for the draw_a_cross function

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It looks like playpen.h does include the prototype for draw_a_cross. I think the error is because drawing_functions.cpp does not #include "drawing_functions.h".

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    124
    I'm not sure if this is the cause of the problem, but...

    Code:
    #ifdef DRAWING_FUNCTIONS_H
    #define DRAWING_FUNCTIONS_H
    Should be...

    Code:
    #ifndef DRAWING_FUNCTIONS_H
    #define DRAWING_FUNCTIONS_H
    Otherwise, DRAWING_FUNCTIONS_H is never defined, which might cause the function prototype never to be interpreted by the compiler.

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    2
    Thanx maxhavoc that little "n" made all the difference! Thanks also to the others who replied.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. funtion pow(x,y) problem
    By g_p in forum C Programming
    Replies: 7
    Last Post: 12-12-2006, 09:18 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. A beginner's problem
    By NewToC in forum C Programming
    Replies: 5
    Last Post: 11-21-2002, 05:20 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM