Thread: No output written to a.out

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    11

    Question No output written to a.out

    Hello,
    I really need to know why my program is not working at all. The entire error message says:
    Code:
    Undefined                       first referenced
     symbol                             in file
    Personal::Personal(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, long)/var/tmp//cchaaWiZ.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status
    Can anyone help me? Here is all of my code. I have been looking at it for hours trying to figure out what is wrong.


    Code:
    //Preprocessor Directives
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    //Personal Class Declaration
    class Personal 
    	{
    	private:
    		string name;
    		string address;
    		int age;
    		long phone;
    		
    	public:
    		Personal();
    		Personal(string, string, int, long);
    
    		void setName(string);
    		void setAddress(string);
    		void setAge(int);
    		void setPhone(long);
    		string getName();
    		string getAddress();
    		int getAge();
    		long getPhone();
    	};
    
    //Class Implementation
    Personal::Personal()
    {
    	name = " ";
    	address = " ";
    	age = 0;
    	phone = 0;
    }
    //Set name function definition
    void Personal::setName(string pname)
    {
    	name = pname;
    }
    //Set address function definition
    void Personal::setAddress(string paddress)
    {
    	address = paddress;
    }
    //Set age function definition
    void Personal::setAge(int page)
    {
    	if(page < 0)
    	{
    		cout << "Invalid, age must be a positive integer." << endl;
    	}
    	else
    		age = page;
    }
    //Set phone function definition
    void Personal::setPhone(long pphone)
    {
    	phone = pphone;
    }
    //Get name function definition
    string Personal::getName()
    {
    	return name;
    }
    //Get address function definition
    string Personal::getAddress()
    {
    	return address;
    }
    //Get age function definition
    int Personal::getAge()
    {
    	return age;
    }
    //Get phone function definition
    long Personal::getPhone()
    {
    	return phone;
    }
    
    //Client Program
    int main()
    {
    	//Temp Variables
    	string personalname;
    	string personaladdress;
    	int personalage;
    	long personalphone;
    	
    	//Instantiate three Personal objects
    	Personal ashley("Ashley", "313 State St.", 21, 3209986);
    	
    	Personal alex("Alex", "705 4th St.", 24, 3402257);
    	
    	Personal input;
    	
    	//Gathering user input for Populating instance input
    	cout << "Please enter your name: " << endl;
    	cin >> personalname;
    	cout << "Please enter your address: " << endl;
    	cin >> personaladdress;
    	cout << "Please enter your age: " << endl;
    	cin >> personalage;
    	cout << "Please enter your phone number: " << endl;
    	cin >> personalphone;
    	
    	//Populates class instance input through set functions
    	input.setName(personalname);
    	input.setAddress(personaladdress);
    	input.setAge(personalage);
    	input.setPhone(personalphone);
    	
    	//Display the data members in the three instances of object Personal
    	cout << left;
    	cout << "Object ashley's contents" << endl;
    	cout << "--------------------------" << endl;
    	cout << setw(20) << "Name: " << ashley.getName() << endl;
    	cout << setw(20) << "Address: " << ashley.getAddress() << endl;
    	cout << setw(20) << "Age: " << ashley.getAge() << endl;
    	cout << setw(20) << "Phone Number: " << ashley.getPhone() << endl;
    	cout << "--------------------------------------------" << endl;
    	
    	cout << "Object alex's contents" << endl;
    	cout << "--------------------------" << endl;
    	cout << setw(20) << "Name: " << alex.getName() << endl;
    	cout << setw(20) << "Address: " << alex.getAddress() << endl;
    	cout << setw(20) << "Age: " << alex.getAge() << endl;
    	cout << setw(20) << "Phone Number: " << alex.getPhone() << endl;
    	cout << "--------------------------------------------" << endl;
    	
    	cout << "Object input's contents" << endl;
    	cout << "--------------------------" << endl;
    	cout << setw(20) << "Name: " << input.getName() << endl;
    	cout << setw(20) << "Address: " << input.getAddress() << endl;
    	cout << setw(20) << "Age: " << input.getAge() << endl;
    	cout << setw(20) << "Phone Number: " << input.getPhone() << endl;
    	cout << "--------------------------------------------" << endl;
    	
    	return 0; 
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Personal::Personal(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, long)/var/tmp//cchaaWiZ.o

    Learn how to read/interpret error messages. The function is declared but never defined.

    >> Personal(string, string, int, long); // <- this needs a function body
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Personal(string, string, int, long);
    You have only declared, but not defined your second constructor.

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    11
    Hi you guys,
    Thanks a lot!!!! It was very useful. I had no idea that I had left such an important part out of my code. Thanks again!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. Problem with my reverse function and its output!
    By Matus in forum C Programming
    Replies: 4
    Last Post: 04-29-2008, 08:33 PM
  4. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  5. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM