Structs/Namespace help "Incomplete Type cannot be defined"

Ive been creating a program for sales and im stuck on the main.cpp portion of the program. I want to create a object for a structure located in my namespace, but i get an error everytime. The error reads:
F:\C++\SalesEx\main.cpp|3|error: expected constructor, destructor, or type conversion before ';' token|
F:\C++\SalesEx\main.cpp||In function 'int main()':|
F:\C++\SalesEx\main.cpp|7|error: aggregate 'SALES::sales Obj' has incomplete type and cannot be defined|
||=== Build finished: 2 errors, 0 warnings ===|


The code i think might cause the problem is highlighted using:
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-

My code:

SalesNmSpce.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef SALESNMSPCE_H_INCLUDED
#define SALESNMSPCE_H_INCLUDED
namespace SALES
{
    const int QUARTERS = 4; //Array size
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    struct sales; //declare structure
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    void _Set(sales & s, const double ar[]); //set sales using an array
    void _InterSet(sales & s); //set sales using cin and cout
    void SortArr(double * Arr); //sort array given
    void _Compute(sales & s); //find average, min and max of data
    void ShowSales(const sales & s); //display results of structure
}
#endif // SALESNMSPCE_H_INCLUDED 


SalesNmSpce.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "SalesNmSpce.h"
#include <iostream>
#include <climits>
///sizeof(array) returns size in bytes, sizeof(double) returns size of the double in bytes. By dividing
///the two together you receive the array length
namespace SALES
{
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    struct sales //structure declaration
    {
        double _Sales[QUARTERS];
        double average;
        double max;
        double min;
    };
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    void _Set(sales & s, const double Ar[])
    {
        double * ar; //temp array
        for(int i = 0; i < sizeof(Ar)/sizeof(double); i++)
            ar[i] = Ar[i]; //copy contents of constant array into temp
        SortArr(ar); //sort the array
        for(int i = 0; i < 4; i++) s._Sales[i] = ar[i]; //grab the lowest values
        _Compute(s); //find average, min and max
    }
    void _InterSet(sales & s)
    {
        double ar[4]; //stores choices by user
        std::cout << "Welcome to the interactive sales gathering program...\n";
        std::cout << "Please input the four values of your quarter sales in order First to Fourth. Ex) 12.3 4 3.2 9\n-- ";
        for(int i = 0; i < 4; i++)
        {
         std::cin >> ar[i]; //read in choice
         s._Sales[i] = ar[i]; //set array to the choice
        }
        _Compute(s);//find average, min and max
    }

    void SortArr(double * Arr)
    {
      int i, j, first, temp;
      int numLength = (sizeof(Arr)/sizeof(double));
      for (i= numLength - 1; i > 0; i--) //start at last point in the array
     {
           first = 0;                 // initialize to subscript of first element
           for (j=1; j<=i; j++)   // locate smallest between positions 1 and i.
          {
                 if (Arr[j] < Arr[first])
                 first = j; //first is the new lowest int found
          }
         temp = Arr[first];   // Swap smallest found with element in position i.
         Arr[first] = Arr[i];
         Arr[i] = temp;
     }

    }

    void _Compute(sales & s)
    {
        double average,max,min; //temporary variables to store data
        max = 0; min = INT_MAX; //INT_MAX is the limit, around 2,000,000,000
        int Length = (sizeof(s._Sales)/sizeof(double)); //calculate length
        for(int i = 0; i < Length;i++)
        {
            if(s._Sales[i] > max) max = s._Sales[i]; //set max and min
            if(s._Sales[i] < min) min = s._Sales[i];
            average += s._Sales[i]; //add onto the average
        }
        ///set values
        s.average = average / Length;
        s.max = max;
        s.min = min;
    }



    void ShowSales(const sales & s) //display results
    {
        std::cout << "--------DISPLAYING SALES REPORT--------\n";
        std::cout << "QUARTER 1:  " << s._Sales[0];
        std::cout << "\tQUARTER 2:  " << s._Sales[1];
        std::cout << "\nQUARTER 3:  " << s._Sales[2];
        std::cout << "\tQUARTER 4:  " << s._Sales[3];
        std::cout << "\n MEAN: " << s.average << " Minimum: " << s.min << " Maximum: " << s.max;
        std::cout << std::endl;
    }
}

main.cpp
[code]
#include <iostream>
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
#include "SalesNMSpce.h" //linking issue maybe?
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
int main()
{
    double __Sales[4] = {12.3,14.97,223.9,1.4}; //create array for setting sales using an array
    //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    SALES::sales Obj; //create sales object(DOES NOT WORK)
     //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    SALES::_Set(Obj,__Sales);
    SALES::ShowSales(Obj);
    std::cout << "Not with interactive: \n";
    SALES::_InterSet(Obj);
    SALES::ShowSales(Obj);
}


Thanks for your time!
Last edited on
You need to give your 'sales' struct a body.

1
2
3
4
struct sales
{
  // put members here
};
Disch wrote:
You need to give your 'sales' struct a body.
He did. In SalesNmSpce.cpp.

That's the problem. You need to do it within your header. In main.cpp the compiler doesn't know what SALES::sales is (it's only a forward declaration).

All the functions in SalesNmSpce.h act like member functions of sales. So why don't you turn in into a class with OOP?
Ah yeah... whoops. I didn't see that.
Coder777, im using exercises in a programming book so i dont want to sway from the original question. I fixed the program though, thanks for the help!
Topic archived. No new replies allowed.