Thread: error: ld returned 1 exit status

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    129

    error: ld returned 1 exit status

    code gave error: ld returned 1 exit status

    What are the wrong in my code

    Code:
    /*C++ program to create student class, Get and display student's details GGC  */ 
    #include <iostream>
    using namespace std;
    
    
    void getDetails(void);
    void DisplayStudentDetails(void);
    
    
    class student
    {
        private:
            char  name[30];
            int   rollNo;
            char  branch[30];
    
    
        public:
            //member function to get student's details
            void getDetails(void)
            {
                 cout << "Enter name: " ;
                 cin >> name;
                 cout << "Enter roll number: ";
                 cin >> rollNo;
                 cout << "Enter Branch: " ;
                 cin >> branch;
            }
            
            //member function to display student's details
            void DisplayStudentDetails(void)
            {
            
                 cout << "Enter name: " ;        
                 cout << "Enter roll number: ";    
                 cout << "Enter Branch: " ;
            }
        protected:
      
    };
     
     
    int main(void)
    {
    
    
     DisplayStudentDetails();   
         
        return 0;
    }
    When I remove line 6 and line 7
    I get new error

    'DisplayStudentDetails' was not declared in this scope
    Last edited by abhi143; 10-29-2019 at 11:37 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Get rid of the declarations on lines 6 and 7. They declare non-member functions, whereas you appear to want member functions.

    In main, declare an object of the student class then use it to call DisplayStudentDetails().
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2017
    Posts
    129
    Quote Originally Posted by laserlight View Post
    Get rid of the declarations on lines 6 and 7. They declare non-member functions, whereas you appear to want member functions.

    In main, declare an object of the student class then use it to call DisplayStudentDetails().
    Thanks that was helpful advice

    Code:
    /*C++ program to create student class, Get and display student's details GGC  */
    #include <iostream>
    using namespace std;
     
     
    void getDetails(void);
    void DisplayStudentDetails(void);
     
    class student
    {
        private:
            char  name[30];
            int   rollNo;
            char  branch[30];
     
        public:
            //member function to get student's details
            void getDetails(void)
            {
                 cout << "Enter name: " ;
                 cin >> name;
                 cout << "Enter roll number: ";
                 cin >> rollNo;
                 cout << "Enter Branch: " ;
                 cin >> branch;
            }
             
            //member function to display student's details
            void DisplayStudentDetails(void)
            {        
                 cout << "name: "  << name <<endl;      
                 cout << "roll number: "  << rollNo <<endl;   
                 cout << "Branch: " << branch  <<endl;      
            }
        protected:
       
    };
      
    int main(void)
    {
       
        // Declare an object of class student 
        student student1; 
         
         student1.getDetails()  ;
      
         student1.DisplayStudentDetails();   
          
        return 0;
    }
    Enter name: abhi
    Enter roll number: 12
    Enter Branch: e
    name: abhi
    roll number: 12
    Branch: e

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: Id returned 5 exit status
    By Quang-vip in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2018, 04:08 AM
  2. error: ld returned 1 exit status
    By vead in forum C Programming
    Replies: 6
    Last Post: 01-19-2018, 11:38 AM
  3. [Error] Id returned 1 exit status
    By iyilikpenisi in forum C Programming
    Replies: 6
    Last Post: 09-16-2016, 02:28 PM
  4. collect2.exe: error: ld returned 1 exit status
    By umutefiloglu in forum C Programming
    Replies: 4
    Last Post: 05-11-2014, 09:37 AM
  5. collect2: ld returned 1 exit status error??
    By blindchicken11 in forum C Programming
    Replies: 11
    Last Post: 11-07-2011, 08:38 PM

Tags for this Thread