Thread: Help with iso c++ forbids declaration of 'parameter' with no type

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12

    Help with iso c++ forbids declaration of 'parameter' with no type

    I need help with trying to figure out why I am getting the error "iso c++ forbids declaration of 'player' with no type" I belive it will solve most of my current errors.

    Here is my program:

    Code:
    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    	void start(int &turn,dominos player[][]){
    
    		for(int i=0;i<7;i++){
    
    			if((player[0][i].num1==6)&&(player[0][i].num2==6)){
    				turn=0;
    				cout<<turn;
    			}
    
    			if((player[1][i].num1==6)&&(player[1][i].num2==6)){
    				turn=1;
    				cout<<turn;
    			}
    
    			if((player[2][i].num1==6)&&(player[2][i].num2==6)){
    				turn=2;
    				cout<<turn;
    			}
    
    			if((player[3][i].num1==6)&&(player[3][i].num2==6)){
    				turn=3;
    				cout<<turn;
    			}
    		}
    	}
    
    	int main(){
    
    		int temp, turn;
    
    		struct dominos{
    			int num1;
    			int num2;
    		};
    
    		dominos deck[28];
    
    		temp=0;
    
    		for(int i=0;i<7;i++){
    
    			deck[i].num1=0;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=1;
    
    		for(int i=7;i<13;i++){
    
    			deck[i].num1=1;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    
    		temp=2;
    
    		for(int i=13;i<18;i++){
    
    			deck[i].num1=2;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=3;
    
    		for(int i=18;i<22;i++){
    
    			deck[i].num1=3;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=4;
    
    		for(int i=22;i<25;i++){
    
    			deck[i].num1=4;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=5;
    
    		for(int i=25;i<27;i++){
    
    			deck[i].num1=5;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=6;
    
    		for(int i=27;i<28;i++){
    
    			deck[i].num1=6;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		srand(time(NULL));
    
    		for(int i=0;i<28;i++){
    
    			dominos shuffle;
    
    			int x=rand()%28;
    
    			shuffle=deck[x];
    			deck[x]=deck[i];
    			deck[i]=shuffle;
    
    			}
    
    
    	/*	for(int i=0;i<28;i++){
    			cout<<"\n"<<deck[i].num1<<"-"<<deck[i].num2;
    		}
    */
    		dominos player[4][7];
    
    		//Player 1;
    
    		for(int i=0;i<7;i++){
    			player[0][i]=deck[i];
    		}
    
    		//Player 2;
    
    		for(int i=0;i<7;i++){
    			player[1][i]=deck[7+i];
    		}
    
    		//Player 3;
    
    		for(int i=0;i<7;i++){
    			player[2][i]=deck[14+i];
    		}
    
    		//player 4;
    
    		for(int i=0;i<7;i++){
    			player[3][i]=deck[21+i];
    		}
    
    		//Player 1;
    
    		cout<<" \n \n Player 1:";
    		for(int i=0;i<7;i++){
    			cout<<" \n"<<player[0][i].num1<<"-"<<player[0][i].num2;
    		}
    
    		//Player 2;
    
    		cout<<" \n \n Player 2:";
    		for(int i=0;i<7;i++){
    			cout<<"\n"<<player[1][i].num1<<"-"<<player[1][i].num2;
    		}
    
    		//Player 3;
    
    		cout<<" \n \n Player 3:";
    		for(int i=0;i<7;i++){
    			cout<<"\n"<<player[2][i].num1<<"-"<<player[2][i].num2;
    		}
    
    		//player 4;
    
    		cout<<" \n \n Player 4:";
    		for(int i=0;i<7;i++){
    			cout<<"\n"<<player[3][i].num1<<"-"<<player[3][i].num2;
    		}
    
    		start(turn, player);
    
    	}
    Here is my compiler errors:

    http://img333.imageshack.us/img333/8480/errors1yi.jpg

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    the declaration of the struct dominos is in main. It is not visible in start().
    put it before the implementation of start().
    Kurt

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Code:
    	void start(int &turn,dominos player[][]){
    . That is not the correct way to declare a 2d array. The second dimension must not be unknown. Example:
    Code:
    int foo(int array[][5])
    {
    }

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    Quote Originally Posted by Ancient Dragon
    Code:
    	void start(int &turn,dominos player[][]){
    . That is not the correct way to declare a 2d array. The second dimension must not be unknown. Example:
    Code:
    int foo(int array[][5])
    {
    }
    even though it's a function? Without using pointers, you'd need a seperate function for each array with a different second dimention?

  5. #5
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >even though it's a function?
    Yep, only the first dimension can be omitted because the "array names become a pointer to the first element" rule only applies to the first dimension of a multi-dimensional array. It's a bummer, but at least you can use a vector of vectors instead.

  6. #6
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12
    Thank you I was able to fix that problem, but I got a new error that I dont understand: "no match for 'operator[]' in"

    Here is my udated program:

    Code:
    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    	void start(int &turn,player[][7]){
    
    		struct dominos{
    			int num1;
    			int num2;
    			};
    
    		dominos player;
    
    		for(int i=0;i<7;i++){
    
    			if((player[0][i].num1==6)&&(player[0][i].num2==6)){
    				turn=0;
    				cout<<turn;
    			}
    
    			if((player[1][i].num1==6)&&(player[1][i].num2==6)){
    				turn=1;
    				cout<<turn;
    			}
    
    			if((player[2][i].num1==6)&&(player[2][i].num2==6)){
    				turn=2;
    				cout<<turn;
    			}
    
    			if((player[3][i].num1==6)&&(player[3][i].num2==6)){
    				turn=3;
    				cout<<turn;
    			}
    		}
    	}
    
    	int main(){
    
    		int temp, turn;
    
    		struct dominos{
    			int num1;
    			int num2;
    		};
    
    		dominos deck[28];
    
    		temp=0;
    
    		for(int i=0;i<7;i++){
    
    			deck[i].num1=0;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=1;
    
    		for(int i=7;i<13;i++){
    
    			deck[i].num1=1;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    
    		temp=2;
    
    		for(int i=13;i<18;i++){
    
    			deck[i].num1=2;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=3;
    
    		for(int i=18;i<22;i++){
    
    			deck[i].num1=3;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=4;
    
    		for(int i=22;i<25;i++){
    
    			deck[i].num1=4;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=5;
    
    		for(int i=25;i<27;i++){
    
    			deck[i].num1=5;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		temp=6;
    
    		for(int i=27;i<28;i++){
    
    			deck[i].num1=6;
    			deck[i].num2=temp;
    
    			temp++;
    
    		}
    
    		srand(time(NULL));
    
    		for(int i=0;i<28;i++){
    
    			dominos shuffle;
    
    			int x=rand()%28;
    
    			shuffle=deck[x];
    			deck[x]=deck[i];
    			deck[i]=shuffle;
    
    			}
    
    
    	/*	for(int i=0;i<28;i++){
    			cout<<"\n"<<deck[i].num1<<"-"<<deck[i].num2;
    		}
    */
    		dominos player[4][7];
    
    		//Player 1;
    
    		for(int i=0;i<7;i++){
    			player[0][i]=deck[i];
    		}
    
    		//Player 2;
    
    		for(int i=0;i<7;i++){
    			player[1][i]=deck[7+i];
    		}
    
    		//Player 3;
    
    		for(int i=0;i<7;i++){
    			player[2][i]=deck[14+i];
    		}
    
    		//player 4;
    
    		for(int i=0;i<7;i++){
    			player[3][i]=deck[21+i];
    		}
    
    		//Player 1;
    
    		cout<<" \n \n Player 1:";
    		for(int i=0;i<7;i++){
    			cout<<" \n"<<player[0][i].num1<<"-"<<player[0][i].num2;
    		}
    
    		//Player 2;
    
    		cout<<" \n \n Player 2:";
    		for(int i=0;i<7;i++){
    			cout<<"\n"<<player[1][i].num1<<"-"<<player[1][i].num2;
    		}
    
    		//Player 3;
    
    		cout<<" \n \n Player 3:";
    		for(int i=0;i<7;i++){
    			cout<<"\n"<<player[2][i].num1<<"-"<<player[2][i].num2;
    		}
    
    		//player 4;
    
    		cout<<" \n \n Player 4:";
    		for(int i=0;i<7;i++){
    			cout<<"\n"<<player[3][i].num1<<"-"<<player[3][i].num2;
    		}
    
    		start(turn, player);
    
    	}

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It's still the same problem. You need to put the player struct definition outside of any function and above any function that uses it. In this case, that means put the struct definition before the start function. Then, you have to give the player array a type like you had originally.

  8. #8
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Try this
    Code:
    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
                
    // globally declare dominos
    struct dominos{
        int num1;
        int num2;
    };
    
    void start(int &turn, dominos player[][7]){
    
    //     dominos player;       // doesn't make sense would hide the parameter
    
    	for(int i=0;i<7;i++){
                 .....
    and remove the declaration of dominos in main().
    Kurt

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Syneris
    even though it's a function? Without using pointers, you'd need a seperate function for each array with a different second dimention?
    you could use double stars
    Code:
    void start(int &turn,dominos **player){

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    even though it's a function? Without using pointers, you'd need a seperate function for each array with a different second dimention?
    You also need a separate function for doubles and ints even though they are both decimal numbers! It may behoove you to know that C++ is a strongly typed language.
    Last edited by 7stud; 01-08-2006 at 05:14 PM.

  11. #11
    Registered User
    Join Date
    Jan 2006
    Location
    Planet X
    Posts
    12
    Thank You!

    That has solved my problem!

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by 7stud
    It may behoove you to know that C++ is a strongly typed language.
    That's not really a very strong claim. It is a stronger typed language than C, but is still far weaker than many other languages.
    Code:
    int a = NULL;
    int b = 0;
    int c = '\0';
    char aa = NULL;
    char bb = 0;
    char cc = '\0';
    int *aaa = NULL;
    int *bbb = 0;
    int *ccc = '\0';
    no problems.
    Just try doing the same thing in Delphi:
    Code:
    var a, b, c : integer;
    var aa, bb, cc : char;
    var aaa, bbb, ccc : intPtr;
    a := nil; //error
    b := 0;
    c := #0; //error
    aa := nil; //error
    bb := 0; //error
    cc := #0;
    aaa := nil;
    bbb := 0; //error
    ccc := #0; //error

  13. #13
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >That's not really a very strong claim.
    Neither is yours. NULL is another way to say 0, so that part of the example is pretty silly. '\0' is also another way to say 0, a char is really a small integer, and a pointer can always be initialized to an expression that evaluates to 0 as meaning a null pointer, so you're basically just showing that you can initialize an int to 0, a char to '\0', and a pointer to null in different but equivalent ways. There's not really an example of weak typing here.

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. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  4. Forbids Declaration with No Type
    By ProgrammingDlux in forum C++ Programming
    Replies: 6
    Last Post: 03-24-2002, 07:39 PM
  5. help, templates and hashing, and yucky stuff like that
    By DarkDays in forum C++ Programming
    Replies: 3
    Last Post: 12-08-2001, 06:01 AM