Thread: Illegal Zero Sized Array?

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    45

    Illegal Zero Sized Array?

    Does anybody know why this error shows? I thought you could make arrays without a set size? heres my code.

    Code:
    #include<iostream.h>
    
    class Movie
    {
    	private:
    		char mTitle[];
    		int mYear;
    		char mDir[];
    	public:
    		void setTitle(char mTitle[]);
    		void setYear(int mYear);
    		void setDirector(char mDir[]);
    		void Display;
    }
    
    int main()
    {
    	Movie myFavoriteMovie;
    	myFavoriteMovie.setTitle(mTitle[]);
    	myFavoriteMovie.setYear(mYear);
    	myFavoriteMovie.setDirector(mDir[]);
    	myFavoriteMovie.Display;
    
    
    }
    
    
    void setTitle(char mTitle[])
    {
    	cout<<"Enter the movie title: ";
    	cin>>mTitle[];
    }
    
    void setYear(int mYear)
    {
    	cout<<"Enter the year the movie was made: ";
    	cin>>mYear;
    }
    
    void setDirector(char mDir[]);
    {
    	cout<<"Enter the directors name: ";
    	cin>>mDir[];
    }
    
    void Display;
    {
    	cout<<"The movie '"<<mTitle[]<<"' was made in "<<mYear<<" and was directed by "<<mDir[]".";
    (i know theres other errors in ther, i just want to get to this one first)

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Look up the new and delete[] commands.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    45
    what does this error meam:

    error C2664: 'setTitle' : cannot convert parameter 1 from 'char' to 'char []'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast


    Code:
    #include<iostream.h>
    
    class Movie
    {
    	private:
    		char mTitle[15];
    		int mYear;
    		char mDir[15];
    	public:
    		void setTitle(char Title[15]);
    		void setYear(int Year);
    		void setDirector(char Dir[15]);
    		void Display();
    };
    
    void main()
    {
    	char Title[15];
    	int Year;
    	char Dir[15];
    
    
    	cout<<"Enter the movie title: ";
    	cin>>Title[15];
    	cout<<"Enter the year the movie was made: ";
    	cin>>Year;
    	cout<<"Enter the directors name: ";
    	cin>>Dir[15];
    
    	Movie myFavoriteMovie;
    	myFavoriteMovie.setTitle(Title[15]);
    	myFavoriteMovie.setYear(Year);
    	myFavoriteMovie.setDirector(Dir[15]);
    	myFavoriteMovie.Display();
    
    
    };
    
    
    void setTitle(char Title[15])
    {
    	strcpy(mTitle[15], Title[15]);
    };
    
    void setYear(int Year)
    {
    	mYear=Year;
    };
    
    void setDirector(char Dir[15]);
    {
    	strcpy(mDir[15], Dir[15]);
    };
    
    void Display();
    {
    	cout<<"The movie '"<<Title[15]<<"' was made in "<<Year<<" and was directed by "<<Dir[15]".";
    }

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    What the deuce? You only need to add the brackets after an array if you're referencing a single character in it, or if it's a definition. Take all of those out of there. They give me headaches.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You need to learn how to use arrays. Stop referencing their size all the time:

    cin>>Title;
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    45
    why are all my variables unidentifiable now?

    Code:
    #include<iostream.h>
    #include<string.h>
    
    class Movie
    {
    	private:
    		char mTitle[15];
    		int mYear;
    		char mDir[15];
    	public:
    		void setTitle(char Title);
    		void setYear(int Year);
    		void setDirector(char Dir);
    		void Display();
    };
    
    void main()
    {
    	char Title;
    	int Year;
    	char Dir;
    
    
    	cout<<"Enter the movie title: ";
    	cin>>Title;
    	cout<<"Enter the year the movie was made: ";
    	cin>>Year;
    	cout<<"Enter the directors name: ";
    	cin>>Dir;
    
    	Movie myFavoriteMovie;
    	myFavoriteMovie.setTitle(Title);
    	myFavoriteMovie.setYear(Year);
    	myFavoriteMovie.setDirector(Dir);
    	myFavoriteMovie.Display();
    
    
    };
    
    
    void setTitle(char Title)
    {
    	strcpy(mTitle, Title);
    };
    
    void setYear(int Year)
    {
    	mYear=Year;
    };
    
    void setDirector(char Dir)
    {
    	strcpy(mDir, Dir);
    };
    
    void Display()
    {
    	cout<<"The movie '"<<Title<<"' was made in "<<Year<<" and was directed by "<<Dir<<".";
    }

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Your functions should be named like so (with namespace):
    Code:
    void Movie::setTitle(char Title)
    {
      /* code here */
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    Sep 2003
    Posts
    45
    the string copy things are the only things giving me problems now....it says:


    error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    And what do you think the problem might be? No point in us telling you all the answers without you pondering about it for a while...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    Registered User
    Join Date
    Sep 2003
    Posts
    45
    i dont understand the error, thats all i was asking was what the error meant, i can figure it out if i knew what it meant. im pretty sure that i used the strcpy command right...or did i do it backwards?

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    What is the difference between these:

    char c;
    char c[10];
    char *c;

    Understand that to understand your problem.

    Oh heck, look, char c is one character only, strcpy() expects two arrays (or pointers to), not two single chars. Find that problem in your code....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM