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 04-Oct-2008, 22:11
kendel kendel is offline
New Member
 
Join Date: Oct 2008
Posts: 1
kendel is on a distinguished road

Error C2664: cannot convert parameter 1 from 'int' to


The problem right now seems to be here:

CPP / C++ / C Code:
string FancyDateClass::getDayOfWeek(void){
	// return the day of week (M, Tu, Wed...) based on the date.  
	// Use the follow equation to calculate a day of week integer: 
	
	int day = julianDate() % 7;
	

	return day;

	// Where: Monday = 0, Tues = 1, Wed = 3
		
} 

And this is the error:
Code:
error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it)' : cannot convert parameter 1 from 'int' to 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it'

CPP / C++ / C Code:
// DateProject.cpp : Defines the entry point for the console application.
//
/*specification: Create a date class with constructors and a destructor */
#include "stdafx.h"


#include <iostream>
#include <sstream>
#include <string>
 
using namespace std;



class FancyDateClass {
private:
    int day;
    int month;
    int year;	
    static int objectCount;
public:

	string toString(void);
	string getMonth(void);
	string getDayOfWeek(void);
	int julianDate(void);
	bool isLeapYear(void);
	
	
	
	
	
	int setDate(int theDay, int theMonth, int theYear);
//	int subtract(FancyDateClass &aDateObj);   
	 void getDate(int &theDay, int &theMonth, int &theYear);
     void displayDate(void);

    
    //constructors
    FancyDateClass(); 
	FancyDateClass(int theDay, int theMonth, int theYear);
	FancyDateClass(const FancyDateClass &aDateObj); 	
     //destructor
    ~FancyDateClass();   
}; 
 
int FancyDateClass::objectCount = 0;
 
//=====================================================================================================================


int main (void){
   


















}
 


//=====================================================================================================================
FancyDateClass::FancyDateClass(){
	//default constructor
	day = 0;
	month = 0;
	year = 0;
	objectCount++;

}

FancyDateClass::FancyDateClass(int theDay, int theMonth, int theYear){
     //parameterized constructor
	 setDate(theDay, theMonth, theYear); 
     objectCount++;
}

FancyDateClass::FancyDateClass(const FancyDateClass &aDateObj) {
	//copy constructor
	day = aDateObj.day;
	month = aDateObj.month;
	year = aDateObj.year;
	objectCount++;
}



FancyDateClass::~FancyDateClass() {
	//destructor
	objectCount--;
	cout << "Number of DateClass objects instantiated " << objectCount << endl; 
}

int FancyDateClass::julianDate(void){
	//return the Julian date for the current date.  The equation to calculate the Julian date is:
    //this conversion algorithm is thanks to the work of Fliegel & Van Flandern

	int theJulianDate = ( 1461 * ( year + 4800 + ( month - 14 ) / 12 ) ) / 4 + ( 367 * ( month - 2 - 12 * ( ( month - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( year + 4900 + ( month - 14 ) / 12 ) / 100 ) ) / 4 + day - 32075;

	return theJulianDate;
}

string FancyDateClass::getDayOfWeek(void){
	// return the day of week (M, Tu, Wed...) based on the date.  
	// Use the follow equation to calculate a day of week integer: 
	
	int day = julianDate() % 7;
	

	return day;

	// Where: Monday = 0, Tues = 1, Wed = 3
		
} 

bool FancyDateClass::isLeapYear(){

	bool leapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));

	return leapYear;
	
}
/* 
	string FancyDateClass::toString(void){
	std::stringstream ss;
	int month = 10;
	string str;
	ss << month;
	ss >> str;

	return month;

} 
*/



int FancyDateClass::setDate(int theDay, int theMonth, int theYear){
	//gives the member variables a value
	//returns an error code if invalid date is entered
	//Error codes: 0 -valid date, 3 - bad year, 2 - bad month, 1 bad day
	
	//check each arguement to ensure it is valid
	int dateCode = 0;

	//check the year
	//check the year
	if(theYear < 1)
		dateCode = 3;
	//check the month

	if(theMonth < 1 || theMonth > 12)
		dateCode = 2;

	//check the day
	int maxDays = 31;
	switch (theMonth) {
		case 2:
			maxDays = 28;
		    break;
		case 4:
		case 6:
		case 9:
		case 11:
			maxDays = 30;
		    break;
		break;
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			maxDays = 31;
			break;
	}
	if (theDay < 1 || theDay > maxDays)
		dateCode = 1;
    
	//set the values right or wrong...
	month = theMonth;
    day = theDay;
	year = theYear;
	
	return dateCode;
}
void FancyDateClass::getDate(int &theDay, int &theMonth, int &theYear){
//set the value of the arguements
	theDay = day;
	theMonth = month;
	theYear = year;
}

void FancyDateClass::displayDate(void) {
	//display the date to the screen
	cout <<"\n\n";
	cout << "day : " << day << endl
		<< "month : " << month << endl
		<< "year : " << year << endl;
}




Last edited by admin : 05-Oct-2008 at 02:16. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 05-Oct-2008, 03:51
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Error C2664: cannot convert parameter 1 from 'int' to


Quote:
Originally Posted by kendel
The problem right now seems to be here:

CPP / C++ / C Code:
string FancyDateClass::getDayOfWeek(void){
	// return the day of week (M, Tu, Wed...) based on the date.  
	// Use the follow equation to calculate a day of week integer: 
	
	int day = julianDate() % 7;
	

	return day;

	// Where: Monday = 0, Tues = 1, Wed = 3
		
} 
Correct. How is method getDayOfWeek() to convert from an int into a string?
  #3  
Old 05-Oct-2008, 10:09
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: Error C2664: cannot convert parameter 1 from 'int' to


in addition to ocicat's reply:
Since int and std::string are different types there is not an automatic conversion between them. You will need to either utilize a std::stringstream (or similar) approach to convert the int to a string or change the return type of the function to be int rather than std::string.
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
 
 

Recent GIDBlogProgramming ebook direct download available 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
Print Japaneese character on Linux terminal & debugging problem rajeshgalla C Programming Language 1 17-Apr-2008 11:57
Print Japaneese character on Linux terminal & debugging problem rajeshgalla C++ Forum 0 14-Apr-2008 02:44
I/O array problem with data files Mr_Peepers C++ Forum 8 21-Feb-2008 20:22
alternate to "assert"for debugging mrz C Programming Language 3 03-Sep-2006 08:45
Memory de-allocation during debugging gaoanyu C Programming Language 12 19-Dec-2005 05:50

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

All times are GMT -6. The time now is 21:13.


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