Thread: compile error

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    92

    compile error

    can a fucntion return multiple values ? probabily use of structure may help to return more than one values.

    i wrote a code, its giving compile error.


    Code:
    #include<iostream>
    using namespace std;
    struct test
    {
    int flag;
    int x;
    char y;
    };
    
    struct func(); // prototype
    
    int main()
    {
    struct test d  = func();
    if (d.flag==1)  { cout<<"char returned"; cout<<d.y;}
    else
    cout<<d.x;
    }
    
    
    struct func()
    {
    struct test c;
    ch='A';
    if(ch<127) // checking whetehr ch is a char
      {
       c.y= ch;
       c.flag=1;
       return c;
      }
    
    else
    {
    c.x = 100;
    c.flag=0;
    return c;
    }
    
    }

    question 1. > why there is error ?

    question 2.> how can i fix those error?
    blue_gene

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > struct func(); // prototype
    You want the name of the struct as well
    struct test func(); // prototype

    Or since this is c++, you can simply do
    test func(); // prototype

    Don't forget to fix the actual function as well
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM