Thread: type 'double' unexpected?

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    28

    Question type 'double' unexpected?

    why does the line: "cout << elements(dArray);" in main() produce a compiler error saying "type 'double' unexpected"? I am using Visual C++.

    #include <iostream>
    #include <cstdlib>
    using namespace std;

    void printAverage(double dArray);

    const int dDIM1 = 3, dDIM2 = 2, dDIM3 = 5, dDIM4 = 2;
    const int SEED = 1000;

    #define elements(array) (sizeof(array)/sizeof(array)/double)

    int main()
    {
    double dArray[dDIM1][dDIM2][dDIM3][dDIM4], *elPtr;
    //double (*elPtr)[dDIM1][dDIM2][dDIM3][dDIM4] = &dArray;
    srand(SEED);
    for(elPtr = (double *)dArray; elPtr < (double *)(&dArray+1); ++elPtr)
    *elPtr = (double)rand();

    cout << dArray[0][0][0][0] << endl;
    cout << dArray[0][0][3][1] << endl;
    cout << dArray[1][0][0][2] << endl;

    cout << elements(dArray);
    //double average = ((dArray[0][0][0][0]) + (dArray[0][0][3][1]) + (dArray[1][0][0][2])) / elements(dArray);
    //cout << average << endl;
    //printAverage(dArray);

    return (0);
    }
    rc7j

  2. #2
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    >> (sizeof(array)/sizeof(array)/double)

    sizeof (array) / sizeof (array)

    = 1 if the precedence is how I think it is.
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    28

    thanks

    That is where the error is. SB: #define elements(array) (sizeof(array)/sizeof(double))
    rc7j

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM