Thread: To Call an Object Outside of Class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Instead of taking two ints, take two Date objects (or whatever type you defined firstDate and secondDate to be) :
    Code:
    bool isLarger(const Date& firstDate, const Date& secondDate)
    {
    	if (firstDate.convert() > secondDate.convert())
    	{
    		cout << "The first date entered is the most recent. " << endl << endl;
    		return true;
    	}
    	else
    	{
    		cout << "The second date entered is the most recent. " << endl << endl;
    		return false;
    	}
    }
    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

  2. #2
    Registered User
    Join Date
    Nov 2007
    Posts
    56
    Thanks for replying so quickly!

    I changed my call to this, and it compiled correctly:
    Code:
    bool isLarger(CDate firstDate, CDate secondDate)
    How do I reference it from the main() function? One of my guesses (and the one with the least errors) was the following, but I received the error message "'CDate' : illegal use of this type as an expression":
    Code:
    isLarger(CDate firstDate, CDate secondDate)
    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM
  2. Is there a way to tell what class an object is?
    By Loduwijk in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2006, 09:20 PM
  3. Linked list of a class object?....
    By chadsxe in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2005, 03:15 PM
  4. array of class object
    By TomButcher in forum C++ Programming
    Replies: 5
    Last Post: 09-03-2005, 09:48 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM