Problem Calling a function from a class
May 14, 2012 at 4:59am UTC
ok so im trying to call on a function so that it can go through do the cout commands but i keep getting a expression must have a class type. im pretty sure its going to be a face palm moment but i cant for the life of me figure it out. heres the coding:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#include <iostream>
#include <iomanip>
using namespace std;
class monthSearch
{
private :
int day;
public :
monthSearch(int x){ day=x;}
void getPrint()
{if ( day>=1 || day<=31)
{
cout << "Day " << day << " falls on January " << day << "." ;
}
else if ( day>=32 || day<=59)
{
cout << "Day " << day << " falls on February " << day-31 << "." ;
}
else if ( day>=60 || day<=90)
{
cout << "Day " << day << " falls on March " << day-59 << "." ;
}
else if ( day>=91 || day<=120)
{
cout << "Day " << day << " falls on April " << day-90 << "." ;
}
else if ( day>=121 || day<=151)
{
cout << "Day " << day << " falls on May " << day-120 << "." ;
}
else if ( day>=152 || day<=181)
{
cout << "Day " << day << " falls on June " << day-151 << "." ;
}
else if ( day>=182 || day<=212)
{
cout << "Day " << day << " falls on July " << day-181 << "." ;
}
else if ( day>=213 || day<=243)
{
cout << "Day " << day << " falls on August " << day-212 << "." ;
}
else if ( day>=244 || day<=273)
{
cout << "Day " << day << " falls on September " << day-243 << "." ;
}
else if ( day>=274 || day<=304)
{
cout << "Day " << day << " falls on October " << day-273 << "." ;
}
else if ( day>=305 || day<=334)
{
cout << "Day " << day << " falls on November " << day-304 << "." ;
}
else if ( day>=335 || day<=365)
{
cout << "Day " << day << " falls on December " << day-334 << "." ;
}
}
};
int main()
{
int Day;
cout << "What day would you like to see the information for? \n(Valid Selection is 1 to 365): " ;
cin >> Day;
monthSearch obj1(int Day);
obj1.getPrint(); // this is where i get the error
}
May 14, 2012 at 5:25am UTC
replace line 72:
monthSearch obj1(int Day);
with:
monthSearch obj1(Day);
Before you were just making a forward declaration, not defining the object.
May 14, 2012 at 9:35am UTC
as Stewbond said, wou were just making a local functon named obj1 that takes an int and returns a montSearch.
May 15, 2012 at 8:39pm UTC
Like I said... Face palm moment..Thanks guys!
Topic archived. No new replies allowed.