|
From: <Tre...@ao...> - 2001-07-30 18:32:11
|
I am learning how to create a class and I need help. After creating the
class and compiling my program I get the following error.
warning C4715: 'Date::assignDate' : not all control paths return a value
This is my class. It is supposed to validate a date entered and display the
date on the screen.
#include <iostream>
using namespace std;
class Date
{
public:
Date();
int assignDate(int, int, int);
void displayDate();
private:
int month;
int day;
int year;
};
Date::Date()
{
month = 0;
day = 0;
year = 0;
} //end of default constructor
int Date::assignDate(int m, int d, int y)
{
month = m;
day = d;
year = y;
if (m >=1 && m <= 12)
{
if (m = 2)
if (y % 4 == 0)
if (d >= 1 && d <= 29)
{
return m;
return d;
return y;
}
else if (d >= 1 && d <= 28)
{
return m;
return d;
return y;
}
else if (m == 4 || m == 6 || m == 9 || m == 11)
if (d >= 1 && d <= 30)
{
return m;
return d;
return y;
}
else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m ==
10 || m == 11)
if (d >= 1 && d <= 31)
{
return m;
return d;
return y;
}
}//end loop
else
cout << "Month does not exist" << endl;
//end ifs
} //end of assignDate function
void Date::displayDate()
{
cout << month << "/" << day << "/" << year;
} //end of displayDate function
|
|
From: Ioannis V. <no...@ya...> - 2001-07-30 18:43:00
|
<http://run.to/noicys>=20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Tre...@ao... Sent: Monday, July 30, 2001 8:32 PM To: dev...@li... Subject: [Dev-C++] Class question I am learning how to create a class and I need help. After creating the class and compiling my program I get the following error.=20 warning C4715: 'Date::assignDate' : not all control paths return a value This is my class. It is supposed to validate a date entered and display the=20 date on the screen. =20 #include <iostream>=20 using namespace std;=20 class Date=20 {=20 public:=20 Date();=20 int assignDate(int, int, int);=20 void displayDate();=20 private:=20 int month;=20 int day;=20 int year;=20 };=20 Date::Date()=20 {=20 month =3D 0;=20 day =3D 0;=20 year =3D 0;=20 } //end of default constructor=20 int Date::assignDate(int m, int d, int y)=20 {=20 month =3D m;=20 day =3D d;=20 year =3D y;=20 if (m >=3D1 && m <=3D 12)=20 {=20 if (m =3D 2)=20 if (y % 4 =3D=3D 0)=20 if (d >=3D 1 && d <=3D 29)=20 {=20 return m;=20 return d;=20 return y;=20 }=20 else if (d >=3D 1 && d <=3D 28)=20 { =20 return m;=20 return d;=20 return y;=20 }=20 else if (m =3D=3D 4 || m =3D=3D 6 || m =3D=3D 9 || m =3D=3D 11)=20 if (d >=3D 1 && d <=3D 30)=20 {=20 return m;=20 =20 These 2 are not returned. return d; =20 return y;=20 }=20 else if (m =3D=3D 1 || m =3D=3D 3 || m =3D=3D 5 || m =3D=3D 7 || m = =3D=3D 8 || m =3D=3D=20 10 || m =3D=3D 11)=20 if (d >=3D 1 && d <=3D 31)=20 {=20 return m; =20 =20 These 2 are not returned. return d;=20 return y;=20 }=20 }//end loop=20 else=20 cout << "Month does not exist" << endl;=20 //end ifs=20 } //end of assignDate function=20 void Date::displayDate()=20 {=20 cout << month << "/" << day << "/" << year;=20 } //end of displayDate function =20 =20 There are probably more errors too, but fix them first. =20 * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com <http://www.noicys.f2s.com/>=20 * Alternative URL: http://run.to/noicys =20 |
|
From: Ray W. <ra...@in...> - 2001-07-31 06:49:58
|
You can only effectively use one return statement in a function,
whether it is a class function or a regular function. The first
'return' statement will cause the function to terminate and return
back to the program which called it.
To return more than one value from a function you need to use
what's called 'call by reference' parameters; your function would
look like this - void AssignDate(int& month, int& day, int& year)
and then the function defination would follow. The '&' symbol
following the type specification allows the function to modify
the actual values passed to it, so somewhere in your function
defination you would want the month = some_value; day = some_other_value;
and year = still_another_value; then you can
use a return statement without a parameter (since function is void)
to terminate the function and lo and behold the variables you
passed to the function will now have the new values in them.
This use of 'call by reference' as opposed to 'call by value' is not
restricted to class methods or functions, but applies to all
functions. The 'call by reference' passes the address of the
variable to the function so that the actual value may be changed,
while the 'call by value' (which is what you get without the '&' only
passes the value of the passed variable and the function cannot modify the
variable which is passed.
bye, ray w.
At 09:43 PM 7/30/01 +0200, you wrote:
> -----Original Message-----
>From: dev...@li...
>[mailto:dev...@li...] On Behalf Of
>Tre...@ao...
>Sent: Monday, July 30, 2001 8:32 PM
>To: dev...@li...
>Subject: [Dev-C++] Class question
>
> After creating the
>class and compiling my program I get the following error.
>
>warning C4715: 'Date::assignDate' : not all control paths return a value
>
> It is supposed to validate a date entered and display the
>
>
><>
>using namespace std;
>
>class Date
>{
>public:
>Date();
>int assignDate(int, int, int);
>void displayDate();
>
>private:
>int month;
>int day;
>int year;
>};
>
>Date::Date()
>{
>month = 0;
> = 0;
> = 0;
>} //end of default constructor
>
>int Date::assignDate(int m, int d, int y)
>{
>month = m;
> = d;
> = y;
>
>>&&<= 12)
>{
>if (m = 2)
>if (y % 4 == 0)
>>&&<= 29)
>{
>return m;
>return d;
>return y;
>}
>>&&<= 28)
>
>return m;
>return d;
>return y;
>}
>else if (m == 4 || m == 6 || m == 9 || m == 11)
>>&&<= 30)
>{
>
> These 2 are not returned. return y;
>}
> else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m ==
>10 || m == 11)
>>&&<= 31)
>{
> These 2 are not returned. return d;
>return y;
>}
>}//end loop
>else
><<<< endl;
>//end ifs
>
>
>} //end of assignDate function
>
>
>void Date::displayDate()
>{
><<<<<<<<<< year;
> There are probably more errors too, but fix them first.
> * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com *
>Alternative URL: http://run.to/noicys
>
Ray Witter
|
|
From: jansb000 <jan...@wx...> - 2001-07-30 19:22:05
|
The error means that inside a conditional statement (like "if then =
else") the compiler has detected that one of the branches is not =
returning any value.
Note: If you use more return statements in a row, only the first one =
will be executed. Returning 3 variables in the way you do is not =
possible. Alternatives are:
- use a class or struct
- use separate functions for dd, mm and yy
- use system clock notation (dd:m:yy are coded in an unsigned long)
----- Original Message -----=20
From: Tre...@ao...=20
To: dev...@li...=20
Sent: Monday, July 30, 2001 8:31 PM
Subject: [Dev-C++] Class question
I am learning how to create a class and I need help. After creating =
the=20
class and compiling my program I get the following error.=20
warning C4715: 'Date::assignDate' : not all control paths return a =
value=20
This is my class. It is supposed to validate a date entered and =
display the=20
date on the screen. =20
#include <iostream>=20
using namespace std;=20
class Date=20
{=20
public:=20
Date();=20
int assignDate(int, int, int);=20
void displayDate();=20
private:=20
int month;=20
int day;=20
int year;=20
};=20
Date::Date()=20
{=20
month =3D 0;=20
day =3D 0;=20
year =3D 0;=20
} //end of default constructor=20
int Date::assignDate(int m, int d, int y)=20
{=20
month =3D m;=20
day =3D d;=20
year =3D y;=20
if (m >=3D1 && m <=3D 12)=20
{=20
if (m =3D 2)=20
if (y % 4 =3D=3D 0)=20
if (d >=3D 1 && d <=3D 29)=20
{=20
return m;=20
return d;=20
return y;=20
}=20
else if (d >=3D 1 && d <=3D 28)=20
{ =20
return m;=20
return d;=20
return y;=20
}=20
else if (m =3D=3D 4 || m =3D=3D 6 || m =3D=3D 9 || m =3D=3D 11)=20
if (d >=3D 1 && d <=3D 30)=20
{=20
return m;=20
return d;=20
return y;=20
}=20
else if (m =3D=3D 1 || m =3D=3D 3 || m =3D=3D 5 || m =3D=3D 7 || m =
=3D=3D 8 || m =3D=3D=20
10 || m =3D=3D 11)=20
if (d >=3D 1 && d <=3D 31)=20
{=20
return m;=20
return d;=20
return y;=20
}=20
}//end loop=20
else=20
cout << "Month does not exist" << endl;=20
//end ifs=20
} //end of assignDate function=20
void Date::displayDate()=20
{=20
cout << month << "/" << day << "/" << year;=20
} //end of displayDate function=20
|
|
From: Richard <ri...@cc...> - 2001-07-30 20:11:12
|
Hi all. I need some help. I have some c source that I wish to compile, =
however I always get a compile error "parse error before '{' " and then =
for the next few lines " nondigits in number and not hexadecimal". The =
code which gives this error is as follows:
void clearscreen() {
__asm {
mov ax,0f00h
int 010h
mov ah,0
int 010h
}
}
Then further on in the program I also get "pares error before 'far' " =
for the following:
word portaddr(int n) { // base address of port LPTn
return(*(word far *)(0x00000408+2*n-2));
}
I can give the source to anyone who would like to examine it, if it =
would help.
Thanks,
Richard
|