Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

struct declaration and definition inside a parameter list

Avatar of runxctry
runxctry asked on
15 Comments1 Solution632 ViewsLast Modified:
This is a piece of code I wrote to demonstrate passing structs as parameters.  The catch is that they are declared WITHIN the parameter list.  Which are not valid, and why they are not valid?  

Context - two compilers that I'm using can't seem to agree what is proper syntax.  One throws syntax errors.  My guess is that the one of the compilers have a bug in it.


#include <iostream.h>

struct three_integer_struct
      int a;
      int b;
      int c;

            int z_a,
            int z_b,
            int z_c
      ) :
      a( z_a ),
      b( z_b ),
      c( z_c ) {};

void display ( three_integer_struct & data )
      cout << data.a <<endl <<data.b <<endl <<data.c <<endl;

void main()
      display ( (three_integer_struct) {1,2,3} );                  // Is this valid?
      display ( three_integer_struct {4,5,6} );                  // Is this valid?
      display ( three_integer_struct hello = {7,8,9} );      // Is this valid?
      display ( three_integer_struct hello {10,11,12} );      // Is this valid?
      display ( three_integer_struct (13,14,15) );            // This is valid.
Avatar of Infinity08
This problem has been solved!
Unlock 1 Answer and 15 Comments.
See Answers