Memo.h:

#ifndef _MEMO_H
#define	_MEMO_H
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>
#include "Date.h"
#include <map>
#include <vector>

using namespace std;

class Memo {
public:
    map<Date, vector<string> > Appointment;
    //void delMemo(int x);
    void addMemo(Date myDate,string x);
};

#endif	/* _MEMO_H *

Memo.cc

#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>
#include "Date.h"
#include <map>
#include "Memo.h"
#include <vector>

using namespace std;

void Memo::addMemo(Date myDate, string myString)
{
    vector<string> appt;
    appt = Appointment[myDate];
    appt.push_back(myString);
    Appointment[myDate] = appt;
}

The above code gives me this compiler output:

Running "/usr/bin/make  -f Makefile CONF=Debug" in /home/josh/Calendar

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/josh/Calendar'
mkdir -p build/Debug/GNU-Linux-x86
g++    -c -g -o build/Debug/GNU-Linux-x86/Memo.o Memo.cc
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_function.h: In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Date]':
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_map.h:418:   instantiated from '_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = Date, _Tp = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, _Compare = std::less<Date>, _Alloc = std::allocator<std::pair<const Date, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
Memo.cc:22:   instantiated from here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_function.h:230: error: no match for 'operator<' in '__x < __y'
make[1]: *** [build/Debug/GNU-Linux-x86/Memo.o] Error 1
make[1]: Leaving directory `/home/josh/Calendar'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.

As a functional exercise, I'm working on a "Memo" class that will work together with my "Date" class to help me create a calendar program.

The "Memo" class, which is what I'm having trouble writing above, will be used to store information into various Dates. I decided to try this by using map<Date, vector<string> > as the storage type as this seems like it'll allow me the flexibility to store multiple strings into any Dates, but without having to use any more space than needed (and allowing the user to store as many strings as they'd like to a specific Date)

The code above doesn't compile correctly. Reading online some it seems I need to pass an operator function to my Memo class. But I'm pretty new to C++ and don't know how to do this correctly at all. I've seen a couple examples of how to, but I'm not sure how I would in my Memo class above. If this is indeed my problem, I'd appreciate help writing the code for this.

Thanks in advance. This seems like a really nice forum and I joined here specifically because it seems a strict philosophy is helping or teaching someone how to do something and not simply offering a solution (I really like that there are practice exercises in the stickies!)

-Josh

EDIT: Oh, I'm using g++ (gcc-4.3.4) as my compiler and write my code in NetBeans IDE 5.5.1. My OS is Gentoo Linux with the 2.6.31-gentoo-r6 kernel

Recommended Answers

All 5 Replies

Memo.h:

#ifndef _MEMO_H
#define	_MEMO_H
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>
#include "Date.h"
#include <map>
#include <vector>

using namespace std;

class Memo {
public:
    map<Date, vector<string> > Appointment;
    //void delMemo(int x);
    void addMemo(Date myDate,string x);
};

#endif	/* _MEMO_H *

Memo.cc

#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>
#include "Date.h"
#include <map>
#include "Memo.h"
#include <vector>

using namespace std;

void Memo::addMemo(Date myDate, string myString)
{
    vector<string> appt;
    appt = Appointment[myDate];
    appt.push_back(myString);
    Appointment[myDate] = appt;
}

The above code gives me this compiler output:

Running "/usr/bin/make  -f Makefile CONF=Debug" in /home/josh/Calendar

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/josh/Calendar'
mkdir -p build/Debug/GNU-Linux-x86
g++    -c -g -o build/Debug/GNU-Linux-x86/Memo.o Memo.cc
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_function.h: In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Date]':
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_map.h:418:   instantiated from '_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = Date, _Tp = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, _Compare = std::less<Date>, _Alloc = std::allocator<std::pair<const Date, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
Memo.cc:22:   instantiated from here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_function.h:230: error: no match for 'operator<' in '__x < __y'
make[1]: *** [build/Debug/GNU-Linux-x86/Memo.o] Error 1
make[1]: Leaving directory `/home/josh/Calendar'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.

As a functional exercise, I'm working on a "Memo" class that will work together with my "Date" class to help me create a calendar program.

The "Memo" class, which is what I'm having trouble writing above, will be used to store information into various Dates. I decided to try this by using map<Date, vector<string> > as the storage type as this seems like it'll allow me the flexibility to store multiple strings into any Dates, but without having to use any more space than needed (and allowing the user to store as many strings as they'd like to a specific Date)

The code above doesn't compile correctly. Reading online some it seems I need to pass an operator function to my Memo class. But I'm pretty new to C++ and don't know how to do this correctly at all. I've seen a couple examples of how to, but I'm not sure how I would in my Memo class above. If this is indeed my problem, I'd appreciate help writing the code for this.

Thanks in advance. This seems like a really nice forum and I joined here specifically because it seems a strict philosophy is helping or teaching someone how to do something and not simply offering a solution (I really like that there are practice exercises in the stickies!)

-Josh

EDIT: Oh, I'm using g++ (gcc-4.3.4) as my compiler and write my code in NetBeans IDE 5.5.1. My OS is Gentoo Linux with the 2.6.31-gentoo-r6 kernel

A map is an ordered data structure, most probably implemented as some form of balanced tree. To enter items into a map the key value, in your case your Date class, needs to provide the operations which will allow the map algorithms to enter the new value in the correct location in the map. In this case a function object which will allow a comparison for less than.
This is indicated by the following line in the error text...

In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Date]':

and the following big chunk of error which is basically telling you that std::less does not know how to work on your Date class.#

The actual line in the compile error text which indocates this is -

error: no match for 'operator<' in '__x < __y'

To fix this you need to define an < operator in your Date class eg.

class Date
{
...
public:
   bool operator<( const Date& rhs ) const
   {
      // in here compare your dates to see which is earlier
      // if this date object is earlier than the one being passed in
      // return true.  don't know your date implementation so 
      // cant speculate 
      return this.date_implmentation < rhs.date_implementation; 
   }
...
};

A map is an ordered data structure, most probably implemented as some form of balanced tree. To enter items into a map the key value, in your case your Date class, needs to provide the operations which will allow the map algorithms to enter the new value in the correct location in the map. In this case a function object which will allow a comparison for less than.
This is indicated by the following line in the error text...

In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Date]':

and the following big chunk of error which is basically telling you that std::less does not know how to work on your Date class.#

The actual line in the compile error text which indocates this is -

error: no match for 'operator<' in '__x < __y'

To fix this you need to define an < operator in your Date class eg.

class Date
{
...
public:
   bool operator<( const Date& rhs ) const
   {
      // in here compare your dates to see which is earlier
      // if this date object is earlier than the one being passed in
      // return true.  don't know your date implementation so 
      // cant speculate 
      return this.date_implmentation < rhs.date_implementation; 
   }
...
};

I wrote up a quick class that I feel should do this here (based on your recommendation):

bool Date::operator<(const Date rhs) const
{
    if(this.Year < rhs.Year)
        return true;
    else if(this.Year==rhs.Year && this.getMonthInt() < rhs.getMonthInt())
        return true;
    else if(this.Year==rhs.Year && this.getMonthInt()==rhs.getMonthInt() && this.Day < rhs.Day)
        return true;
    else 
        return false;
}

This gives me a new set of errors though:

Running "/usr/bin/make  -f Makefile CONF=Debug" in /home/josh/Calendar

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/josh/Calendar'
mkdir -p build/Debug/GNU-Linux-x86
g++    -c -g -o build/Debug/GNU-Linux-x86/Date.o Date.cc
Date.cc: In member function 'bool Date::operator<(const Date&) const':
Date.cc:227: error: request for member 'Year' in 'this', which is of non-class type 'const Date* const'
Date.cc:229: error: request for member 'Year' in 'this', which is of non-class type 'const Date* const'
Date.cc:229: error: request for member 'getMonthInt' in 'this', which is of non-class type 'const Date* const'
Date.cc:229: error: passing 'const Date' as 'this' argument of 'int Date::getMonthInt()' discards qualifiers
Date.cc:231: error: request for member 'Year' in 'this', which is of non-class type 'const Date* const'
Date.cc:231: error: request for member 'getMonthInt' in 'this', which is of non-class type 'const Date* const'
Date.cc:231: error: passing 'const Date' as 'this' argument of 'int Date::getMonthInt()' discards qualifiers
Date.cc:231: error: request for member 'Day' in 'this', which is of non-class type 'const Date* const'
make[1]: *** [build/Debug/GNU-Linux-x86/Date.o] Error 1
make[1]: Leaving directory `/home/josh/Calendar'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.

I've tried removing const from the function with similar results. I see it makes Date a pointer? (..."which is of non-class type 'const Date* const'")

So I then tried turning changing everything with "this. ...." or "rhs. ..." into "&this. ..." and "&rhs. ..." respectively to use their references instead. This did nothing for changing the errors, though

I'll post my Date class and header files here:
Date.h:

#ifndef _DATE_H
#define	_DATE_H
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>

using namespace std;

class Date {
protected:
    string strMonth;
    string strFullDate;
    string getMonthStr();
    int getMonthInt();
public:
    int Month;
    int Day, Year;
    string getStr();
    void setDate(int m, int d, int y);
    void setDate(string m, int d, int y);
    Date();
    bool isLeapYear();
    bool isValid();
    string day();
    bool operator<(const Date rhs) const;
};

Date.cc: (with new operator function added at the end)

#include <stdlib.h>
#include <string>
#include <iostream>
#include <typeinfo>
#include "Date.h"
#include <sstream>

using namespace std;

Date::Date() 
{
    Month=0;
}
string Date::getMonthStr()
{
    if(Month==0)
        return strMonth;
    else
    {
        switch(Month)
        {
            case 1:
                return "January";
            case 2:
                return "February";
            case 3:
                return "March";
            case 4:
                return "April";
            case 5:
                return "May";
            case 6:
                return "June";
            case 7:
                return "July";
            case 8:
                return "August";
            case 9:
                return "September";
            case 10:
                return "October";
            case 11:
                return "November";
            case 12:
                return "December";
        }
    }
}
int Date::getMonthInt()
{
    if(Month!=0)
        return Month;
    else
    {
        if(strMonth=="January")
            return 1;
        else if(strMonth=="February")
            return 2;
        else if(strMonth=="March")
            return 3;
        else if(strMonth=="April")
            return 4;
        else if(strMonth=="May")
            return 5;
        else if(strMonth=="June")
            return 6;
        else if(strMonth=="July")
            return 7;
        else if(strMonth=="August")
            return 8;
        else if(strMonth=="September")
            return 9;
        else if(strMonth=="October")
            return 10;
        else if(strMonth=="November")
            return 11;
        else if(strMonth=="December")
            return 12;
    }
}
void Date::setDate(int m, int d, int y)
{
    Month = m;
    Day = d;
    Year = y;
}

void Date::setDate(string m, int d, int y)
{
    strMonth = m;
    Day = d;
    Year = y;
}
string Date::getStr()
{
    string day, year;
    stringstream outD;
    outD << Date::Day;
    day = outD.str();
    stringstream outY;
    outY << Date::Year;
    year = outY.str();
    
    string tempStr = "";       
    tempStr.append(getMonthStr());
    tempStr.append(" ");
    tempStr.append(day);
    tempStr.append(", ");
    tempStr.append(year);
    return tempStr;
}
bool Date::isValid()
{
    Month = getMonthInt();
    bool validDate = false;
    if(Month==1)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==2)
    {
        if(Day==29)
        {
            if(Year%4 == 0)
            {
                validDate = true;
                if(Year%100==0)
                    validDate = false;
                if(Year%400==0)
                    validDate = true;
            }
        }
        else
        {
            if(Day<=28 && Day>=1)
                validDate = true;
        }
    }
    else if(Month==3)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==4)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==5)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==6)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==7)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==8)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==9)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==10)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==11)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==12)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    return validDate;
}
bool Date::isLeapYear()
{
    bool leapYear = false;
    if(Year%4 == 0)
    {
        leapYear = true;
        if(Year%100==0)
            leapYear = false;
        if(Year%400==0)
            leapYear = true;
    }
    return leapYear;
}
string Date::day()
{
    Month = getMonthInt();
    string dayOfWeek[7] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
    int tempMonth=0;
    if(Month>=3)
        tempMonth = Month;
    else
        tempMonth = Month+12;
    int intday = (Day + (((tempMonth+1)*26)/10 ) + Year + (Year/4) + 6*(Year/100) + (Year/400) )%7;
    return dayOfWeek[intday];
}
bool Date::operator<(const Date rhs) const
{
    if(this.Year < rhs.Year)
        return true;
    else if(this.Year==rhs.Year && this.getMonthInt() < rhs.getMonthInt())
        return true;
    else if(this.Year==rhs.Year && this.getMonthInt()==rhs.getMonthInt() && this.Day < rhs.Day)
        return true;
    else 
        return false;1
}

I wrote the operator function like above because the way a date is set is with 3 separate integers: Month, Day, Year. So I'd need to compare them to decide whether one Date is indeed before another Date

Even with "const" removed from the function above, the error changes slightly to "which is of non-class type 'Date* const'" instead

I'm assuming it's because the operator function isn't able to change the variables it compares?

How would I go about fixing this issue?

Thanks again for your help and explanation. It helped a lot in understanding a few things at once. I feel it's close to functioning how I'd like now once this error is resolved.

-Josh

'this' is always a pointer, so e.g. this.Year is wrong, it has to be this->Year . operator <() is 'const', that means that every class method you call inside it, must also be 'const', in this case it means getMonthInt() . Then again, you might directly access the .Month member variable.

To avoid unnecessary temporary objects, consider passing rhs by reference, i.e.

bool Date::operator<(const Date & rhs) const;

The last post should correct your issues.

In this case you have to pass the Date as a const Date& because this is the operator signature that is expected. But you are almost there.

On a side note, whilst your date representation will probably do what you want it to do there are simpler ways of achieving this. One example would be to reference all dates as a number of seconds past an arbitrary time in the past. With such a representation date comparisons are simply a matter of of comparing an integer value. It is worthwhile researching this further. Try googling for a bit. And take a look at this...

http://en.wikipedia.org/wiki/Unix_time


heading out in a min but just to be sure here is an example of a simplified program doing what you want (taken from online msdn).

// functional_less.cpp
#include <vector>
#include <algorithm>
#include <functional>
#include <iostream>

struct MyStruct {
   MyStruct(int i) : m_i(i){}
   
   bool operator < (const MyStruct & rhs) const {
      return m_i < rhs.m_i;
   }   

   int m_i;
};

int main() {
   using namespace std;
   vector <MyStruct> v1;
   vector <MyStruct>::iterator Iter1;
   vector <MyStruct>::reverse_iterator rIter1;

   int i;
   for ( i = 0 ; i < 7 ; i++ )     
       v1.push_back( MyStruct(rand()));

   cout << "Original vector v1 = ( " ;
   for ( Iter1 = v1.begin() ; Iter1 != v1.end() ; Iter1++ ) 
      cout << Iter1->m_i << " ";
   cout << ")" << endl;

   // To sort in ascending order,
   sort( v1.begin( ), v1.end( ), less<MyStruct>());

   cout << "Sorted vector v1 = ( " ;
   for ( Iter1 = v1.begin() ; Iter1 != v1.end() ; Iter1++ ) 
      cout << Iter1->m_i << " ";
   cout << ")" << endl;
 }

Works with vectors but exlpains how to do the <operator.

Okay, so I think I've solved the issue with the operator function for the Date class and I've finished getting a somewhat functional version of my Date class and Memo class.

Below is the code for anyone who's interested:
Date.h:

#ifndef _DATE_H
#define	_DATE_H
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>

using namespace std;

class Date {
protected:
    string strFullDate;
    string getMonthStr();
public:
    int Month;
    int Day, Year;
    string getStr();
    void setDate(int m, int d, int y);
    Date()
    {
        Month = 0;
        Day = 0;
        Year = 0;
    }
    bool isLeapYear();
    bool isValid();
    string day();
    bool operator < (const Date &rhs) const;
};


#endif	/* _DATE_H */

Date.cc:

#include <stdlib.h>
#include <string>
#include <iostream>
#include <typeinfo>
#include "Date.h"
#include <sstream>

using namespace std;

void Date::setDate(int m, int d, int y)
{
    Month = m;
    Day = d;
    Year = y;
}
string Date::getMonthStr()
{
    switch(Month)
    {
        case 1:
            return "January";
        case 2:
            return "February";
        case 3:
            return "March";
        case 4:
            return "April";
        case 5:
            return "May";
        case 6:
            return "June";
        case 7:
            return "July";
        case 8:
            return "August";
        case 9:
            return "September";
        case 10:
            return "October";
        case 11:
            return "November";
        case 12:
            return "December";
    }
}
string Date::getStr()
{
    string day, year;
    stringstream outD;
    outD << Date::Day;
    day = outD.str();
    stringstream outY;
    outY << Date::Year;
    year = outY.str();
    
    string tempStr = "";       
    tempStr.append(getMonthStr());
    tempStr.append(" ");
    tempStr.append(day);
    tempStr.append(", ");
    tempStr.append(year);
    return tempStr;
}
bool Date::isValid()
{
    bool validDate = false;
    if(Month==1)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==2)
    {
        if(Day==29)
        {
            if(Year%4 == 0)
            {
                validDate = true;
                if(Year%100==0)
                    validDate = false;
                if(Year%400==0)
                    validDate = true;
            }
        }
        else
        {
            if(Day<=28 && Day>=1)
                validDate = true;
        }
    }
    else if(Month==3)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==4)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==5)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==6)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==7)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==8)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==9)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==10)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    else if(Month==11)
    {
        if(Day<=30 && Day>=1)
            validDate = true;
    }
    else if(Month==12)
    {
        if(Day<=31 && Day>=1)
            validDate = true;
    }
    return validDate;
}
bool Date::isLeapYear()
{
    bool leapYear = false;
    if(Year%4 == 0)
    {
        leapYear = true;
        if(Year%100==0)
            leapYear = false;
        if(Year%400==0)
            leapYear = true;
    }
    return leapYear;
}
string Date::day()
{
    string dayOfWeek[7] = {"Saturday", "Sunday", "Monday", "intuesday", "Wednesday", "inthursday", "Friday"};
    int tempMonth=0;
    if(Month>=3)
        tempMonth = Month;
    else
        tempMonth = Month+12;
    int intday = (Day + (((tempMonth+1)*26)/10 ) + Year + (Year/4) + 6*(Year/100) + (Year/400) )%7;
    return dayOfWeek[intday];
}
bool Date::operator < (const Date &rhs) const
{
    if(Year < rhs.Year)
        return true;
    else if(Year==rhs.Year && Month < rhs.Month)
        return true;
    else if(Year==rhs.Year && Month==rhs.Month && Day < rhs.Day)
        return true;
    else 
        return false;
}

Memo.h:

#ifndef _MEMO_H
#define	_MEMO_H
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>
#include "Date.h"
#include <map>
#include <vector>

using namespace std;

class Memo {
public:
    map<Date, vector<string> > Appointment;
    void delMemo(Date myDate, int x);
    void addMemo(Date myDate,string x);
    void getMemo(Date myDate);
};

#endif	/* _MEMO_H */

Memo.cc:

#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <iostream>
#include "Date.h"
#include <map>
#include "Memo.h"
#include <vector>

using namespace std;

void Memo::addMemo(Date myDate, string myString)
{
    vector<string> appt;
    appt = Appointment[myDate];
    appt.push_back(myString);
    Appointment[myDate] = appt;
}
void Memo::getMemo(Date myDate)
{
    vector<string> appt;
    appt = Appointment[myDate];
    for(int x=0; x<appt.size(); x++)
    {
        cout << x << ": " << appt[x] << endl;
    }
}
void Memo::delMemo(Date myDate, int x)
{
    vector<string> appt;
    appt = Appointment[myDate];
    appt.erase(appt.begin()+x);
    Appointment[myDate] = appt;
}

I'm pretty new to C++ and am pretty proud of pulling this off :D. I've been reading the C++ All-In-One Desk Reference for Dummies (7 Books in 1 version) by Jeff Cogswell. I'm up to page 564 now, my second time reading through the book (furthest I've gotten though). And with what I've learned from the book and the help here I was able to write a small functional program that shows these classes working together:

#include <stdlib.h>
#include "Date.h"
#include "Memo.h"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char** argv) {
    Date MyDate;
    MyDate.setDate(3,3,2010);
    string validity;
    if(MyDate.isValid())
        validity = "True";
    else
        validity = "False";
    cout << MyDate.getStr() << endl << "Valid?: " << validity << endl;
    if(MyDate.isLeapYear())
        validity = "True";
    else
        validity = "False";
    cout << "Leap year: " << validity << endl;
    cout << "Day of week: " << MyDate.day() << endl;
    cout << "********* START SAVE MEMO *********" << endl;
    Memo MyMemo;
    MyMemo.addMemo(MyDate, "testing");
    MyMemo.addMemo(MyDate, "another test");
    cout << "Outputting contents of memo for MyDate" << endl;
    MyMemo.getMemo(MyDate);
    MyMemo.delMemo(MyDate,0);
    cout << "Outputting contents of memo for MyDate" << endl;
    MyMemo.getMemo(MyDate);
    return (0);
}

This is my first time making use of a class I had written in another class that I'd written...and using both together in a small program. The program may be fairly simple but it helped me understand a lot of concepts and it was nice to see them all working as expected.

Next, to learn how to make a GUI program...preferably that's compatible with Linux (Gnome) and Windows. I have little to no experience in this area either and C++ for Dummies seems to only explain how to write a Windows Application with the Widnows API

Your responses helped me a lot in both understanding the code and getting my code to do what I was hoping for. I'm hoping to write a GUI calendar program using these classes, so as I work on this, I'll work through some of the challenges and examples found in the stickies here

Once again, thank you for your help! :)
-Josh

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.