Thread: question on classes

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    question on classes

    ok im working with classes trying to figure them out i have the idea down you make a class to create objects like int,string etc. to make your variable types and stuff. so i copied this program out of the book and it compiles fine no errors however when i goto execute it i get the following errors and any explanation on the syntax of this would be appreciated as well cant seem to grasp that part to well either:

    --------------------Configuration: displaydate - Win32 Debug--------------------
    Linking...
    displaydate.obj : error LNK2001: unresolved external symbol "public: void __thiscall date::assigndate(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,
    class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?assigndate@date@@QAEXV?$basic_string@DU?$char_tr aits@D@std@@V?$allocator@D@2@@std@@00@Z)
    Debug/displaydate.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    displaydate.exe - 2 error(s), 0 warning(s)





    Code:
    #include <string>
    using namespace std;
    class date
    {
    public:
    //intializes variables
    date();
    //assigns program values to variables
    void assigndate(string,string,string);
    //returns formatted date
    string getdate();
    private:
    string month;
    string day;
    string year;
    };
    
    //pmplentation section
    date::date()
    {
    //constructor
    month = "";
    day = "";
    year = "";
    } // end of assigndate function
    
    string date::getdate()
    {
    return month + "/" + day + "/" + year;
    }//end of getdate function
    Code:
    #include <iostream>
    #include <string>
    #include "date.h"
    using namespace std;
    
    int main()
    {
    	//create object
    	date dateobj;
    
    	//declare variables
    	string hiremonth = "";
    	string hireday = "";
    	string hireyear = "";
    
    	//get month day and year
    	cout << "Enter the month: ";
    	getline(cin,hiremonth);
    	cout << "Enter the day: ";
    	getline(cin,hireday);
    	cout << "Enter the year: ";
    	getline(cin,hireyear);
    
    	//set the date
    	dateobj.assigndate(hiremonth,hireday,hireyear);
    
    	//display the date
    	cout << "Employee hire date " << dateobj.getdate() << endl;
    
    	return 0;
    
    }
    hooch

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include <string>
    using namespace std;
    class date
    {
    public:
    //intializes variables
    date();
    //assigns program values to variables
    void assigndate(string,string,string);
    //returns formatted date
    string getdate();
    private:
    string month;
    string day;
    string year;
    };
    
    //pmplentation section
    date::date()
    {
    //constructor
    month = "";
    day = "";
    year = "";
    } // end of assigndate function
    
    string date::getdate()
    {
    return month + "/" + day + "/" + year;
    }//end of getdate function
    Code:
    #include <iostream>
    #include <string>
    #include "date.h"
    using namespace std;
    
    int main()
    {
        //create object
        date dateobj;
    
        //declare variables
        string hiremonth = "";
        string hireday = "";
        string hireyear = "";
    
        //get month day and year
        cout << "Enter the month: ";
        getline(cin,hiremonth);
        cout << "Enter the day: ";
        getline(cin,hireday);
        cout << "Enter the year: ";
        getline(cin,hireyear);
    
        //set the date
        dateobj.assigndate(hiremonth,hireday,hireyear);
    
        //display the date
        cout << "Employee hire date " << dateobj.getdate() << endl;
    
        return 0;
    
    }
    You are trying to call a function that you haven't coded yet it seems. You have a declaration in the class, but no actual code for that function anywhere.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    In your first file, you have the declaration of
    void assigndate(string,string,string);
    in the class but you don't have a implementation/definition of it.

    Notice how date() and getdate() both have a declaration above and a definition below.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    yes i seemed to of overlooked that somehow lol

    Code:
    void date::assigndate(string m, string d, string y)
    {
    	month = m;
    	day = d;
    	year = y;
    }
    ok well with that solved im still confused with this syntax here. but let me see if i got it? or at least some idea to work with.

    you create an object class date it then has its own things that it can do in this case display the date using the numbers the user inputs?

    so to do this i have to get it to determine out of what is inputed what the day,the month, and the year is? so like any object like cin for example it has how many arguements er (var,var2,var3,etc) it can take.

    i think that is a general round about idea of what it does though the syntax is still confusing? any help on clearing that up would be great!
    hooch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes question...
    By Raigne in forum C++ Programming
    Replies: 24
    Last Post: 09-12-2006, 01:46 AM
  2. Replies: 2
    Last Post: 07-28-2006, 02:59 PM
  3. Simple Question about Classes
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2006, 02:40 AM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. Newbie question about the Private type in classes
    By Ryeguy457 in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2002, 10:17 PM