Pointer Trouble (GCC complains)

This is a discussion on Pointer Trouble (GCC complains) within the C++ Programming forums, part of the General Programming Boards category; When trying to compile this: Code: #include <iostream> using namespace std; void DoubleIt(int *pointer); int main () { int a ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    7

    Pointer Trouble (GCC complains)

    When trying to compile this:

    Code:
    #include <iostream>
    
    using namespace std;
    
    void DoubleIt(int *pointer);
    
    int main ()
    {
      int a = 0;
      int b = 0;
      
      //int *ptr_a = &a;
      //int *ptr_b = &b;
      
      cout << "Enter a value for a: ";
      cin >> a;
      
      cout << "Enter a value for b: ";
      cin >> b;
      
      cout << "Double a is " << DoubleIt(&a) << ".\n";
      cout << "Double b is " << DoubleIt(&b) << ".\n";
      
      return 0;
    }
    
    void DoubleIt(int *pointer)
    {
      *pointer *= 2;
    }
    GCC says this:
    Code:
    $ g++ doubleit.cpp -o doubleit                                                      
    doubleit.cpp: In function ‘int main()’:                                                                  
    doubleit.cpp:22: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"Double a is ")) << DoubleIt(ptr_a)’
    (and a WHOLE lot more (looks like mostly the same message though)).

    This strikes me as strange, because it seems to be complaining about I/O, but as far as I can tell there aren't any syntax errors. I've been looking at this for about an hour and can't figure out what's wrong.

    Any ideas?

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    DoubleIt returns void (doesn't return anything).

    You are using its return values
    Code:
      cout << "Double a is " << DoubleIt(&a) << ".\n";
      cout << "Double b is " << DoubleIt(&b) << ".\n";

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    7
    .... Oh man... *FACEPALM* I think it's time for bed. lol. Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  4. ascii and pointer trouble!!!
    By algi in forum C++ Programming
    Replies: 1
    Last Post: 11-16-2004, 02:00 PM
  5. Double Pointer Trouble
    By Rhodium in forum C Programming
    Replies: 8
    Last Post: 05-23-2003, 11:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21