Thread: Error C2365....Please

  1. #1
    Registered User
    Join Date
    Aug 2014
    Posts
    26

    Question Error C2365....Please

    Goal:
    Use a struct that has 4 fields, input to those fields, and pass to function to display.


    Problem:
    (38) : error C2365: 'displaySData' : redefinition; previous definition was 'data variable'




    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    //prototypes
    void displaySData(MovieData, MovieData);
    
    
    struct MovieData
    {
        string Title;
        string Director;
        string YearReleased;
        string RunTime;
    };
    
    
    int main()
    {
        MovieData data1;
        MovieData data2;
    
    
        // Get input for struct var 1
        cout<<"Enter the title of the movie:\n";
        cin>>data1.Title;
        cout<<"Enter the director of the movie:\n";
        cin>>data1.Director;
        // Get input for struct var 2
        cout<<"Enter the release date (year) of the movie:\n";
        cin>>data2.YearReleased;
        cout<<"Enter the run time (minutes) of the movie:\n";
        cin>>data2.RunTime;
        // Function for display
        displaySData(data1, data2);
        system("Pause");
        return 0;
    }
    
    
    void displaySData(MovieData d1, MovieData d2)
    {
        cout<<d1.Title<<"\n";
        cout<<d1.Director<<"\n";
        cout<<d2.YearReleased<<"\n";
        cout<<d2.RunTime<<"\n";
    }

    C++ Masters.. Please help me..

  2. #2
    Registered User
    Join Date
    Aug 2014
    Posts
    26
    Quote Originally Posted by c_lover View Post
    goal:
    use a struct that has 4 fields, input to those fields, and pass to function to display.


    problem:
    (38) : Error c2365: 'displaysdata' : Redefinition; previous definition was 'data variable'




    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    //prototypes
    void displaysdata(moviedata, moviedata);
    
    
    struct moviedata
    {
        string title;
        string director;
        string yearreleased;
        string runtime;
    };
    
    
    int main()
    {
        moviedata data1;
        moviedata data2;
    
    
        // get input for struct var 1
        cout<<"enter the title of the movie:\n";
        cin>>data1.title;
        cout<<"enter the director of the movie:\n";
        cin>>data1.director;
        // get input for struct var 2
        cout<<"enter the release date (year) of the movie:\n";
        cin>>data2.yearreleased;
        cout<<"enter the run time (minutes) of the movie:\n";
        cin>>data2.runtime;
        // function for display
        displaysdata(data1, data2);
        system("pause");
        return 0;
    }
    
    
    void displaysdata(moviedata d1, moviedata d2)
    {
        cout<<d1.title<<"\n";
        cout<<d1.director<<"\n";
        cout<<d2.yearreleased<<"\n";
        cout<<d2.runtime<<"\n";
    }

    c++ masters.. Please help me..
    nevermind

  3. #3
    Registered User
    Join Date
    Aug 2014
    Posts
    26
    Quote Originally Posted by c_lover View Post
    nevermind
    I just switched the prototype and struct

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    >>void displaySData(MovieData, MovieData);
    This is not helpful. At all. What parameters does the function take? Sure, I can see the type, but that tells me nothing in this case.
    For example, this:
    void DrawCircle(int, int, int);
    What are the parameters? Clearly you can understand why this is so bad. You should always include the name of the parameters in the prototype (at the very least):
    void DrawCircle(int x, int y, int radius);

    For that matters, d1 and d2 are not very descriptive names.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile error? Logic error? Syntax Error? Please help
    By Khody Afkhami in forum C Programming
    Replies: 4
    Last Post: 10-11-2014, 01:36 AM
  2. Replies: 6
    Last Post: 10-29-2012, 03:33 AM
  3. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  4. Replies: 1
    Last Post: 11-15-2010, 11:14 AM
  5. Replies: 3
    Last Post: 10-02-2007, 09:12 PM

Tags for this Thread