operator>> not found error

So, I was building this code recently and I got some errors (seems obvious right, hold off on the sarcasm for awhile please). Anyway, the errors specifically were:


packages.cpp:586:34: error: expected primary-expression before ‘;’ token
packages.cpp:620:15: error: no match for ‘operator>>’ in ‘std::cin >> *(p + ((long unsigned int)(((long unsigned int)i) * 8ul)))’
packages.cpp:623:20: error: ‘getCharge’ was not declared in this scope

I'm pretty sure the other two errors were caused by the same bug that caused the 2nd one but I'm not really sure why it's happening. Here's the offending code:


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
int main()
{
  // Variable Declarations
  package **p = NULL;
  short siNumPackages, siNumDimensions;

  // Greeting
  cout << endl << "Hello! Welcome to Planet Express's virtual package delivery"
       << " service." << endl;

  // Input for the number of packages
  cout << endl << "Input how many packages you need delivered today ";
  cin >> siNumPackages;

  p = new package[siNumPackages]*; // Error 2

  // For every package . . .
  for (short i = 0; i < siNumPackages; i++)
  {
    // Input number of dimensions (with error handling)
    do
    {
      cout << endl << "Input how many dimensions the package has ";
      cin >> siNumDimensions;

      if ((siNumDimensions > 4) || (siNumDimensions < 2))
        cout << endl << "This company is only certified to carry 2, 3 and 4 "
             << "dimensional packages. Try again! ";
    } while ((siNumDimensions > 4) || (siNumDimensions < 2));

    // Assign package type to element in p
    switch (siNumDimensions)
    {
      case 2:
      {
        p[i] = new pak2D;
        break;
      }
      case 3:
      {
        p[i] = new pak3D;
        break;
      }
      case 4:
        p[i] = new pak4D;
    }

    // Input packages
    cin >> p[i];   // Error 2

    // Get charge
    getCharge(*p[i]);  // Error 3

    // Output package
    cout << endl << "#" << i << p[i];
  }

  // Deallocate Memory
  delete [] p;
  p = NULL;


Any tips would be great if you've got them.
Last edited on
You probably didnt overload your package class
Please use code tags tho, itd make it alot easier to read and you'd prolly get more answers faster
Ok, so forget about Error 3. That was a snafu in actually calling the function.
Error 2:

you have
p = new package[siNumPackages]*

try

p = new package*[siNumPackages]
Last edited on
Thanks TheJJJunk.

I'm implementing the solutions now. I'll tell you if it works.

Angeljruiz, what do you mean by overloading the class?
Last edited on
Well I fixed Error 2, it was as TheJJJunk pointed out.

However, all the derived classes have been declared correctly as far as I can tell.
Ok, I've fixed the issue. The problem was that my input operator functions for the derived and base classes were declared virtual (and therefore, couldn't be declared as friends). As such, the correct code would have been

*p[i] >> cin;

or something similar. Anyway, I un-virtualized the overloaded functions and made them friends and now the error is gone
Topic archived. No new replies allowed.