GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Jun-2006, 21:46
jdbrine jdbrine is offline
Junior Member
 
Join Date: May 2006
Posts: 56
jdbrine is on a distinguished road

Compile Errors


I'm having several compile errors that I am not understanding. My code and errors are below, inserted after lines of code for convenience, along with what I think the problem is:

//Driver.cpp

CPP / C++ / C Code:
#include <iostream>
#include <string>
#include <ctime>
#include "Date.h"
#include "Person.h"

using namespace std;

int main()
{
	string askinfo;
	string writeinfo;

	struct tm *currday;


	time_t long_time;
	time(&long_time);

	currday=localtime(&long_time);
	int day;
	int month;
	int year;

	year = currday ->tm_year + 1900;
	month=currday ->tm_mon + 1;
	day=currday->tm_mday;

	int ans;
	cout << "Jerry Brinegar - Summer 2006" << endl;
	cout << "CP 278B C++ Programming Part 2" << endl;
	cout << "Program 4 - 6/24/2006" << endl;
	cout << "\n";
	cout << "\n";
	cout << "Classes/Person and Date" << endl;
	cout << "Today's Date is: ";
	cout << month << "/" << day << "/" << year << endl;


	Person Pal;


	do
	{

		askinfo=Pal.AskUserForPerson();

/*C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP4\Driver.cpp(50) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)*/

		writeinfo=Pal.WritePersonToScreen();
/*C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP4\Driver.cpp(51) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)*/


		cout << '\n';
		cout << "Do you want to go again? 1 - yes, 2 - no ";
		cin >> ans;
		
	}while (ans!=2);


return 0;

}

I think these two are because my return type is void in my function definition in my class? So I would either change to string type, or just have Pal.AskUserForPerson() as my call?

//Date.cpp
CPP / C++ / C Code:
#include <iostream>
#include <string>
#include <ctime>
#include "Date.h"
#include "Person.h"

using namespace std;

Date::Date()
{
SetDate(7, 5, 2006, "today");
DayOfYear=186;
}

void Date::SetDate(int m, int d, int y, string desc)
{

	month=m;
	day=d;
	year=y;
	description=desc;



}

int Date::GetDay()
/*C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP4\Date.cpp(32) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
*/
int Date::GetMonth()
/*C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP4\Date.cpp(32) : error C2143: syntax error : missing ';' before 'tag::id'
C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP4\Date.cpp(32) : fatal error C1004: unexpected end of file found
Error executing cl.exe.*/

int Date::GetYear()
int Date::GetDayOfYear()


void Date::GetFormattedDate()

{


}


I'm not sure what is causing these.

Other relevant files:

//Person.cpp
CPP / C++ / C Code:
#include <iostream>
#include <string>
#include <sstream>
#include "Date.h"
#include "Person.h"

using namespace std;

Person::Person()
{
	

}


void Person::AskUserForPerson()
{

	int mnth;
	int dy;
	int yr;
	string dsc;

	mnth=bday.GetMonth();
	dy=bday.GetDay();
	yr=bday.GetYear();

	cout << "Enter the person's name: " ;

	cin >> name;


	cout << "Enter the birthday (m/d/y): ";
	cin >>  mnth,dy,yr;

	bday.SetDate(mnth,dy,yr,dsc);
	
}

void Person::WritePersonToScreen()
{

cout << "Person's Name is: " << name;


}
//Date.h
CPP / C++ / C Code:

#include <string>

using namespace std;

class Date
{
private:
	int month, day, year;
	string description;
	int DayOfYear;

public:
	Date();									//constructor object with system date 7/5/2006
	//Date(int m, int d, int y, string desc);	//constructor for input values
	void SetDate(int m, int d, int y, string desc);	//sets Date object to input values

	string GetFormattedDate();	//returns the date and year description in formatted string

	int GetDayOfYear();			//returns day of year 1-365
	int GetYear() {return year;}
	int GetMonth() {return month;}
	int GetDay() {return day;}
};
//Person.h
CPP / C++ / C Code:

#include <string>


class Person
{
private:
	string name;
	Date tday;				//system date
	Date bday;
	int age;				//person's age in years
	int daysToFromBDay;		//number of days to/from birthday
	bool bhadABirthday;		//true if birthday has already occurred, false if not

	void CalcDaysToFromBDay();
	void CalculateAge();


public:
	Person();					//constructor initializes values to zero/null
	void AskUserForPerson();	//asks for the name and birthday
								//calls CalcAge() and CalcDays()

	void WritePersonToScreen();

};
  #2  
Old 30-Jun-2006, 00:24
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Compile Errors


The error:
CPP / C++ / C Code:
askinfo=Pal.AskUserForPerson();
/*C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - 
Visual C++\CP 287B C++\BrinegarP4\Driver.cpp(50) : error C2679: 
binary '=' : no operator defined which takes a right-hand operand 
of type 'void' (or there is no acceptable conversion)*/
(please note I put the error on multiple lines so it can be read)

Error Dissection:
binary '=' : no operator defined: you don't have an = operator for the types you are trying to set equal.

right-hand operand of type 'void': Right side of the = (Pal.AskUserForPerson()) is a void value.

CPP / C++ / C Code:
string askinfo;
askinfo is obviously a string type

CPP / C++ / C Code:
class Person
{
...
	void AskUserForPerson();	//asks for the name and birthday
...
}
AskUserForPerson() returns nothing. How can you set a string to nothing?

This should start you on your way...
__________________

Age is unimportant -- except in cheese
  #3  
Old 30-Jun-2006, 01:33
amad1337's Avatar
amad1337 amad1337 is offline
Junior Member
 
Join Date: Dec 2004
Posts: 54
amad1337 will become famous soon enough

Re: Compile Errors


//Date.cpp
CPP / C++ / C Code:

int Date::GetDay() //wrong, the statement need to end with ;

int Date::GetMonth()


int Date::GetYear()
Those functions are already defined in the header, Date.h, as inline function. So remove the functions from the implementation file, Date.cpp.


//Date.cpp
CPP / C++ / C Code:

int Date::GetDayOfYear() 


But this one is just declared in the header, Date.h. So you need to implement it here.
  #4  
Old 30-Jun-2006, 11:11
jdbrine jdbrine is offline
Junior Member
 
Join Date: May 2006
Posts: 56
jdbrine is on a distinguished road

Re: Compile Errors


Yes, that's what I was thinking and what I stated in my post Re: binary= compile errors.

I think these two are because my return type is void in my function definition in my class? So I would either change to string type, or just have Pal.AskUserForPerson() as my call?

amad1337 thanks for the info.
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile Errors due to Default Parameters jdbrine C++ Forum 1 17-Jun-2006 14:45
Compile errors earachefl C++ Forum 3 24-Feb-2006 16:49
conditional compile logic cable_guy_67 C++ Forum 15 03-Dec-2005 18:44
Help with compiler errors Krandygrl00 C++ Forum 3 01-Jun-2005 07:45
Linker errors with multiple file progam nkhambal C Programming Language 2 24-Apr-2005 02:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:38.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.