Thread: Won't compile, can YOU compile it on your compiler?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Won't compile, can YOU compile it on your compiler?

    // Listing 15.7
    //demonstrates use of an array of pointers to functions

    #include <iostream>
    using namespace std;

    void Square (int&,int&);
    void Cube (int&, int&);
    void Swap (int&, int &);
    void GetVals(int&, int&);
    void PrintVals(int, int);

    int main()
    {
    int valOne=1, valTwo=2;
    int choice, i;
    const MaxArray = 5;
    void (*pFuncArray[MaxArray])(int&, int&);

    for (i=0;i<MaxArray;i++)
    {
    cout << "(1)Change Values (2)Square (3)Cube (4)Swap: ";
    cin >> choice;
    switch (choice)
    {
    case 1: pFuncArray[i] = GetVals; break;
    case 2: pFuncArray[i] = Square; break;
    case 3: pFuncArray[i] = Cube; break;
    case 4: pFuncArray[i] = Swap; break;
    defaultFuncArray[i] = 0;
    }
    }

    for (i=0;i<MaxArray; i++)
    {
    if ( pFuncArray[i] == 0 )
    continue;
    pFuncArray[i](valOne,valTwo);
    PrintVals(valOne,valTwo);
    }
    return 0;
    }

    void PrintVals(int x, int y)
    {
    cout << "x: " << x << " y: " << y << endl;
    }

    void Square (int & rX, int & rY)
    {
    rX *= rX;
    rY *= rY;
    }

    void Cube (int & rX, int & rY)
    {
    int tmp;

    tmp = rX;
    rX *= rX;
    rX = rX * tmp;

    tmp = rY;
    rY *= rY;
    rY = rY * tmp;
    }

    void Swap(int & rX, int & rY)
    {
    int temp;
    temp = rX;
    rX = rY;
    rY = temp;
    }

    void GetVals (int & rValOne, int & rValTwo)
    {
    cout << "New value for ValOne: ";
    cin >> rValOne;
    cout << "New value for ValTwo: ";
    cin >> rValTwo;
    }

    Ok it's been 3 consecutives example from the book that won't compile.....this is an example from STYC++ in 21 Days......Does it compile on your compiler.....by the way I see the problem in it I just want to know.const MaxArray = 5; <-- no return value declared......
    Last edited by incognito; 03-09-2002 at 09:39 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using DXUT with Borland 5.5 free compiler
    By Jedi Nescioquis in forum Game Programming
    Replies: 7
    Last Post: 02-11-2009, 12:04 PM
  2. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  3. Can't compile on the other compiler
    By AProg in forum C Programming
    Replies: 8
    Last Post: 05-25-2003, 07:55 AM
  4. My Dev compiler won't compile
    By Unregistered in forum C++ Programming
    Replies: 22
    Last Post: 05-04-2002, 06:37 PM
  5. Special Compiler for win app's
    By Unregistered in forum Windows Programming
    Replies: 19
    Last Post: 04-26-2002, 03:52 PM