|
-
Apr 14th, 2001, 09:37 PM
#1
Thread Starter
Registered User
hello, i'm still learning C++, and i just converted to VC++ and i have no idea whats going on, because i don't nkow what goes where and i get werid errors, like where do i #include the headers at.? and where do i put the main(){} and where do i write teh body of the fucntion (defining them) here is my code and i get 2 errors....
Code:
//factor.h
#include <iostream.h>
#include "factor.cpp"
//interface
typedef unsigned short int USHORT;
Err_Code factor(USHORT n, USHORT &rSquared, USHORT &rCubed)
{
if (n => 20)
return FAILURE;
{
else
rSquared = n*n;
rCubed = n*n*n;
return SUCCESS;
}
}
errors i get:
--------------------Configuration: Mutlireturn value with ref and enumeration - Win32 Debug--------------------
Compiling...
factor.cpp
c:\program files\microsoft visual studio\myprojects\mutlireturn value with ref and enumeration\factor.h(4) : warning C4182: #include nesting level is 363 deep; possible infinite recursion
c:\program files\microsoft visual studio\myprojects\mutlireturn value with ref and enumeration\factor.h(4) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
Error executing cl.exe.
Mutlireturn value with ref and enumeration.exe - 1 error(s), 1 warning(s)
------------------------------------------------------------------------------
.cpp file
Code:
#include "factor.h"
//prototype
enum Err_Code { SUCCESS,FAILURE }; //sucess = 0, failure = 1
Err_Code factor(USHORT, USHORT&, USHORT&);
int main()
{
USHORT number, squared, cubed;
Err_Code Result;
cout <<"Enter a number (1-20)" << endl;
cin >> number;
Result = factor(number, squared, cubed);
if(Result == SUCCESS)
{
cout <<"number: " << number << "\n";
cout <<"squared: " << squared << "\n";
cout <<"cubed: " << cubed << "\n";
else
cout <<"Number is too large" << end;
}
return 0;
}
can someone tell me what i did wrong?
and where i am suppose to put everyting at where i mixed it up?
thanks for listening
-
Apr 15th, 2001, 07:37 PM
#2
Frenzied Member
The reason you are getting those errors is because the files are including each other. Factor.h includes the file factor.cpp, which includes factor.h, which includes factor.cpp..... etc. The #include preprocessor instruction simply replaces the #include line with the contents of the file you are #include-ing. So both files contain each other, and you get an infinite recursion. The compiler fails because eventually it runs out of memory to store all the code in. The solution is to remove the line #include "factor.cpp". You shouldn't #include .cpp files anyway, only header files (.h or .hpp).
The parameters are already being passed by reference anyway, you don't need to change it to work with pointers, although you should make sure you are fully aware of what references are if you are going to use them.
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|