compile error

This is a discussion on compile error within the C++ Programming forums, part of the General Programming Boards category; can a fucntion return multiple values ? probabily use of structure may help to return more than one values. i ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06: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

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