Board index » cppbuilder » Re: Class problems

Re: Class problems


2004-09-12 10:42:22 AM
cppbuilder27
Start by cleaning up the code.
The function main returns an int. It does not return void.
You exit from main with a return statement such as
return 0;
You do NOT exit from main by calling exit.
C++ functions, including constructors and destructors, that take no
arguments have () and not (void).
If you have a problem then post compilable source.
. Ed
Quote
Mark Manning/Muniz Eng. wrote in message
news:4143ab20$ XXXX@XXXXX.COM ...

I recently got the Borland C++v5.02 compiler et al. I've done work
with C++ for years but the compiler is frustrating me.

I am making a simple "create a name" program for our D&D game and
I've made a class called "Name". It looks like this:

/////////////////////////////////////////////////////////////////
enum { gUC, gLC }; // Upper and lowercase ENUMs
enum { gMale, gFemale ); // Character's gender

class Name
{
private:
<my variables>

public:
Name( void );
~Name( void );

full( void ); // Return the full name.
human( long optA ); // Create a human name.
elf( long optA ); // Create an elven name.
};
////////////////////////////////////////////////////////////////

The main program looks like this:

////////////////////////////////////////////////////////////////
#include "main.h"

void
main( int argc, char *argv[] )
{
Name myName;

printf( "gUC = %d\n", gUC );
myName.human( gMale );
printf( "My name is: %s\n", myName.full() );
exit( 0 );
}
////////////////////////////////////////////////////////////////

All of the functions are properly set in name.cpp. Like so:

////////////////////////////////////////////////////////////////
#include "main.h"

Name::Name( void )
{
<Code to init the names>
}

Name::~Name( void )
{
}

Name::full( void )
{
return( m_full );
}

Name::human( long optA )
{
<Code to create a human name>
}

Name::elf( long optA )
{
<Code to create an elven name>
}
///////////////////////////////////////////////////////////////////

The "main.h" file contains all of the includes to the various
classes.

///////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
.
.
.
#include "name.h"
///////////////////////////////////////////////////////////////////

Ok! Now that you have all of that information - here is the
question:

When I compile - it likes everything. But when it reaches the
linker stage I get:

Undefined Name::~Name()
Undefined Name::human( long optA )
Undefined Name::full()

I've checked all of the functions. I've tried commenting out each
of the above one after the other - no other error messages are
coming out of the linker. Also, the first printf statement does not
give an error about gUC. So I know it is getting name.h loaded.

Why would the linker not like the functions themselves? Also, under
gcc this compiles without a problem (linux) but Borland C++ v5.02
dies. My next plan of attack is to delete and redo the project's
file. Maybe that is the answer. I recently decided to move
everything to a separate subfolder (called Character). So maybe the
project file is messed up somehow. Unknown but if you have an idea
I'd like to hear from you. ( XXXX@XXXXX.COM ).

TIA to anyone who has an idea on this problem. :-)
 
 

Re:Re: Class problems

Actually,
void main( int argc, char *argv[] ) is perfectly valid as long as exit
is not used. I misread my printout. So yes - it should be int with the
exit command but I should have left off the exit command in my example.
According to my book on C++ (as well as the several classes I've
written, compiled, and run here at work not to mention the several
courses I've had about C++) using void in a deconstructor is ok. You do
not have to do that - but it can be done and it will have no bad side
effects. Also, I've already tried removing the void within the
deconstructor and the error remains. So I know that is not the problem.
As for the quip "If you have a problem then post compilable source." If
having to change one line in order to make it compile is too much for
you then I'd rather wait for someone else to help me. Maybe they will
focus on the problem at hand.
Now, if you would like me to send you the actual code - I can do that
and would be glad to do so. I can just create a zip file and send it to
you of the entire directory structure as well as all of the source code
files and project file (minus the object files and compiled program).
Didn't want to post tons of pages so I posted what I thought (doing a
single pass from the printout since I am at work presently) was a
reasonable job of transferring the basic problem into this post. But if
you would like to see the entire thing - I can send you that as well.
Just give me an e-mail address to send it to and then give me about an
hour or two because I first have to make it back home.
Later.
Ed Mulroy [TeamB] wrote:
Quote
Start by cleaning up the code.

The function main returns an int. It does not return void.

You exit from main with a return statement such as
return 0;
You do NOT exit from main by calling exit.

C++ functions, including constructors and destructors, that take no
arguments have () and not (void).

If you have a problem then post compilable source.

. Ed


>Mark Manning/Muniz Eng. wrote in message
>news:4143ab20$ XXXX@XXXXX.COM ...
>
>I recently got the Borland C++v5.02 compiler et al. I've done work
>with C++ for years but the compiler is frustrating me.
>
>I am making a simple "create a name" program for our D&D game and
>I've made a class called "Name". It looks like this:
>
>/////////////////////////////////////////////////////////////////
>enum { gUC, gLC }; // Upper and lowercase ENUMs
>enum { gMale, gFemale ); // Character's gender
>
>class Name
>{
>private:
><my variables>
>
>public:
>Name( void );
>~Name( void );
>
>full( void ); // Return the full name.
>human( long optA ); // Create a human name.
>elf( long optA ); // Create an elven name.
>};
>////////////////////////////////////////////////////////////////
>
>The main program looks like this:
>
>////////////////////////////////////////////////////////////////
>#include "main.h"
>
>void
>main( int argc, char *argv[] )
>{
>Name myName;
>
>printf( "gUC = %d\n", gUC );
>myName.human( gMale );
>printf( "My name is: %s\n", myName.full() );
>exit( 0 );
>}
>////////////////////////////////////////////////////////////////
>
>All of the functions are properly set in name.cpp. Like so:
>
>////////////////////////////////////////////////////////////////
>#include "main.h"
>
>Name::Name( void )
>{
><Code to init the names>
>}
>
>Name::~Name( void )
>{
>}
>
>Name::full( void )
>{
>return( m_full );
>}
>
>Name::human( long optA )
>{
><Code to create a human name>
>}
>
>Name::elf( long optA )
>{
><Code to create an elven name>
>}
>///////////////////////////////////////////////////////////////////
>
>The "main.h" file contains all of the includes to the various
>classes.
>
>///////////////////////////////////////////////////////////////////
>#include <stdio.h>
>#include <stdlib.h>
>.
>.
>.
>#include "name.h"
>///////////////////////////////////////////////////////////////////
>
>Ok! Now that you have all of that information - here is the
>question:
>
>When I compile - it likes everything. But when it reaches the
>linker stage I get:
>
>Undefined Name::~Name()
>Undefined Name::human( long optA )
>Undefined Name::full()
>
>I've checked all of the functions. I've tried commenting out each
>of the above one after the other - no other error messages are
>coming out of the linker. Also, the first printf statement does not
>give an error about gUC. So I know it is getting name.h loaded.
>
>Why would the linker not like the functions themselves? Also, under
>gcc this compiles without a problem (linux) but Borland C++ v5.02
>dies. My next plan of attack is to delete and redo the project's
>file. Maybe that is the answer. I recently decided to move
>everything to a separate subfolder (called Character). So maybe the
>project file is messed up somehow. Unknown but if you have an idea
>I'd like to hear from you. ( XXXX@XXXXX.COM ).
>
>TIA to anyone who has an idea on this problem. :-)



 

Re:Re: Class problems

I am replying for two reasons:
1. To let you know that I am now home and can send you a zipped file of
everything.
2. To say that, after thinking about it on the way home I now understand
your posting about compilable code.
Let me address this. The reason I did not place any code in the
functions is because: 1)I have already tried putting #if 0/#endif around
all of the code in the functions. It doesn't matter if I remove the
code completely or comment it out or put the #if 0/#endif, 2)Originally,
the main program had nothing in it. When all commands are removed from
the main program everything compiles and does not complain. Only when I
attempt to use the class does the IDE complain, and 3)It is the linker
and not the compiler which is complaining. The compiler seems to like
everything just fine.
This is why I stated that I was going to try redoing the project file.
I have already had to do this once before because the Project file
started acting very strange. Not being able to find/locate the source
files and such. So that is what I am going to try now that I have gone
through all of the permutations with the source code I am going outside
of the source and seeing if one of the other files used by the IDE is
causing a problem. If not - what can I say?
Mark
Ed Mulroy [TeamB] wrote:
Quote
Start by cleaning up the code.

The function main returns an int. It does not return void.

You exit from main with a return statement such as
return 0;
You do NOT exit from main by calling exit.

C++ functions, including constructors and destructors, that take no
arguments have () and not (void).

If you have a problem then post compilable source.

. Ed


>Mark Manning/Muniz Eng. wrote in message
>news:4143ab20$ XXXX@XXXXX.COM ...
>
>I recently got the Borland C++v5.02 compiler et al. I've done work
>with C++ for years but the compiler is frustrating me.
>
>I am making a simple "create a name" program for our D&D game and
>I've made a class called "Name". It looks like this:
>
>/////////////////////////////////////////////////////////////////
>enum { gUC, gLC }; // Upper and lowercase ENUMs
>enum { gMale, gFemale ); // Character's gender
>
>class Name
>{
>private:
><my variables>
>
>public:
>Name( void );
>~Name( void );
>
>full( void ); // Return the full name.
>human( long optA ); // Create a human name.
>elf( long optA ); // Create an elven name.
>};
>////////////////////////////////////////////////////////////////
>
>The main program looks like this:
>
>////////////////////////////////////////////////////////////////
>#include "main.h"
>
>void
>main( int argc, char *argv[] )
>{
>Name myName;
>
>printf( "gUC = %d\n", gUC );
>myName.human( gMale );
>printf( "My name is: %s\n", myName.full() );
>exit( 0 );
>}
>////////////////////////////////////////////////////////////////
>
>All of the functions are properly set in name.cpp. Like so:
>
>////////////////////////////////////////////////////////////////
>#include "main.h"
>
>Name::Name( void )
>{
><Code to init the names>
>}
>
>Name::~Name( void )
>{
>}
>
>Name::full( void )
>{
>return( m_full );
>}
>
>Name::human( long optA )
>{
><Code to create a human name>
>}
>
>Name::elf( long optA )
>{
><Code to create an elven name>
>}
>///////////////////////////////////////////////////////////////////
>
>The "main.h" file contains all of the includes to the various
>classes.
>
>///////////////////////////////////////////////////////////////////
>#include <stdio.h>
>#include <stdlib.h>
>.
>.
>.
>#include "name.h"
>///////////////////////////////////////////////////////////////////
>
>Ok! Now that you have all of that information - here is the
>question:
>
>When I compile - it likes everything. But when it reaches the
>linker stage I get:
>
>Undefined Name::~Name()
>Undefined Name::human( long optA )
>Undefined Name::full()
>
>I've checked all of the functions. I've tried commenting out each
>of the above one after the other - no other error messages are
>coming out of the linker. Also, the first printf statement does not
>give an error about gUC. So I know it is getting name.h loaded.
>
>Why would the linker not like the functions themselves? Also, under
>gcc this compiles without a problem (linux) but Borland C++ v5.02
>dies. My next plan of attack is to delete and redo the project's
>file. Maybe that is the answer. I recently decided to move
>everything to a separate subfolder (called Character). So maybe the
>project file is messed up somehow. Unknown but if you have an idea
>I'd like to hear from you. ( XXXX@XXXXX.COM ).
>
>TIA to anyone who has an idea on this problem. :-)



 

{smallsort}

Re:Re: Class problems

Ok, figured it out myself. :-)
I had made everything in the project:
myProg
+---->main.cpp
+----->name.cpp
.
.
.
When main.cpp compiled it could not find the subsets under it. By
moving all of the sub-functions to be on the same level as main.cpp main
could find them and work with them.
Strange but true. Would have thought that since all of the classes are
being used by the main program that they would/could be hung off of
main.cpp. But no. The compiler doesn't like it like that. Ah well.
And it only took me about two hours to figure this out. No book (can't
find it but it is around here someplace), the SAM'S book on C++ Builder
is no help, and of course none of the other books on C++ that I have
help because this is something unique to Borland C++'s IDE. :-/ What
can I say?
Oh well, back to my tinkering with the program. :-)
Mark
Ed Mulroy [TeamB] wrote:
Quote
Start by cleaning up the code.

The function main returns an int. It does not return void.

You exit from main with a return statement such as
return 0;
You do NOT exit from main by calling exit.

C++ functions, including constructors and destructors, that take no
arguments have () and not (void).

If you have a problem then post compilable source.

. Ed


>Mark Manning/Muniz Eng. wrote in message
>news:4143ab20$ XXXX@XXXXX.COM ...
>
>I recently got the Borland C++v5.02 compiler et al. I've done work
>with C++ for years but the compiler is frustrating me.
>
>I am making a simple "create a name" program for our D&D game and
>I've made a class called "Name". It looks like this:
>
>/////////////////////////////////////////////////////////////////
>enum { gUC, gLC }; // Upper and lowercase ENUMs
>enum { gMale, gFemale ); // Character's gender
>
>class Name
>{
>private:
><my variables>
>
>public:
>Name( void );
>~Name( void );
>
>full( void ); // Return the full name.
>human( long optA ); // Create a human name.
>elf( long optA ); // Create an elven name.
>};
>////////////////////////////////////////////////////////////////
>
>The main program looks like this:
>
>////////////////////////////////////////////////////////////////
>#include "main.h"
>
>void
>main( int argc, char *argv[] )
>{
>Name myName;
>
>printf( "gUC = %d\n", gUC );
>myName.human( gMale );
>printf( "My name is: %s\n", myName.full() );
>exit( 0 );
>}
>////////////////////////////////////////////////////////////////
>
>All of the functions are properly set in name.cpp. Like so:
>
>////////////////////////////////////////////////////////////////
>#include "main.h"
>
>Name::Name( void )
>{
><Code to init the names>
>}
>
>Name::~Name( void )
>{
>}
>
>Name::full( void )
>{
>return( m_full );
>}
>
>Name::human( long optA )
>{
><Code to create a human name>
>}
>
>Name::elf( long optA )
>{
><Code to create an elven name>
>}
>///////////////////////////////////////////////////////////////////
>
>The "main.h" file contains all of the includes to the various
>classes.
>
>///////////////////////////////////////////////////////////////////
>#include <stdio.h>
>#include <stdlib.h>
>.
>.
>.
>#include "name.h"
>///////////////////////////////////////////////////////////////////
>
>Ok! Now that you have all of that information - here is the
>question:
>
>When I compile - it likes everything. But when it reaches the
>linker stage I get:
>
>Undefined Name::~Name()
>Undefined Name::human( long optA )
>Undefined Name::full()
>
>I've checked all of the functions. I've tried commenting out each
>of the above one after the other - no other error messages are
>coming out of the linker. Also, the first printf statement does not
>give an error about gUC. So I know it is getting name.h loaded.
>
>Why would the linker not like the functions themselves? Also, under
>gcc this compiles without a problem (linux) but Borland C++ v5.02
>dies. My next plan of attack is to delete and redo the project's
>file. Maybe that is the answer. I recently decided to move
>everything to a separate subfolder (called Character). So maybe the
>project file is messed up somehow. Unknown but if you have an idea
>I'd like to hear from you. ( XXXX@XXXXX.COM ).
>
>TIA to anyone who has an idea on this problem. :-)



 

Re:Re: Class problems

"Mark Manning/Muniz Eng." <mark@glab>writes:
Quote
void main( int argc, char *argv[] ) is perfectly valid as long as exit
is not used.
No. Both the C and the C++ language have always required the return type
of main() to be int. The ISO Standards for the languages require compilers
to produce a diagnostic message if the return type is different from void.
There are many buggy compilers out there, including, I think all Borland
has ever released, that let you get away with main()'s return type being
void, but that doesn't make doing it any more correct.
 

Re:Re: Class problems

Quote
void main( int argc, char *argv[] ) is perfectly valid as long as
exit is not used.
void main is incorrect. The standards for the C and C++ languages
both specify that main is a function whose return type is int. There
is no relationship between this and the use of the function exit.
Quote
Now, if you would like me to send you the actual code ...
I wanted you to massage what you are using down to a stub of around 50
lines or less which compiles and which retains one or more of the
problems you are having and post that in a message.
Quote
... I'd rather wait for someone else to help me. ...
Sounds like a good idea.
Quote
Mark Manning/Muniz Eng. wrote in message
news: XXXX@XXXXX.COM ...
Actually,

void main( int argc, char *argv[] ) is perfectly valid as long as
exit is not used. I misread my printout. So yes - it should be int
with the exit command but I should have left off the exit command in
my example.

According to my book on C++ (as well as the several classes I've
written, compiled, and run here at work not to mention the several
courses I've had about C++) using void in a deconstructor is ok.
You do not have to do that - but it can be done and it will have no
bad side effects. Also, I've already tried removing the void within
the deconstructor and the error remains. So I know that is not the
problem.

As for the quip "If you have a problem then post compilable source."
If having to change one line in order to make it compile is too much
for you then I'd rather wait for someone else to help me. Maybe
they will focus on the problem at hand.

Now, if you would like me to send you the actual code - I can do
that and would be glad to do so. I can just create a zip file and
send it to you of the entire directory structure as well as all of
the source code files and project file (minus the object files and
compiled program). Didn't want to post tons of pages so I posted
what I thought (doing a single pass from the printout since I am at
work presently) was a reasonable job of transferring the basic
problem into this post. But if you would like to see the entire
thing - I can send you that as well. Just give me an e-mail address
to send it to and then give me about an hour or two because I first
have to make it back home.

Later.

Ed Mulroy [TeamB] wrote:
>Start by cleaning up the code.
>
>The function main returns an int. It does not return void.
>
>You exit from main with a return statement such as
>return 0;
>You do NOT exit from main by calling exit.
>
>C++ functions, including constructors and destructors, that take no
>arguments have () and not (void).
>
>If you have a problem then post compilable source.
>
>. Ed
>
>
>>Mark Manning/Muniz Eng. wrote in message
>>news:4143ab20$ XXXX@XXXXX.COM ...
>>
>>I recently got the Borland C++v5.02 compiler et al. I've done work
>>with C++ for years but the compiler is frustrating me.
>>
>>I am making a simple "create a name" program for our D&D game and
>>I've made a class called "Name". It looks like this:
>>
>>/////////////////////////////////////////////////////////////////
>>enum { gUC, gLC }; // Upper and lowercase ENUMs
>>enum { gMale, gFemale ); // Character's gender
>>
>>class Name
>>{
>>private:
>><my variables>
>>
>>public:
>>Name( void );
>>~Name( void );
>>
>>full( void ); // Return the full name.
>>human( long optA ); // Create a human name.
>>elf( long optA ); // Create an elven name.
>>};
>>////////////////////////////////////////////////////////////////
>>
>>The main program looks like this:
>>
>>////////////////////////////////////////////////////////////////
>>#include "main.h"
>>
>>void
>>main( int argc, char *argv[] )
>>{
>>Name myName;
>>
>>printf( "gUC = %d\n", gUC );
>>myName.human( gMale );
>>printf( "My name is: %s\n", myName.full() );
>>exit( 0 );
>>}
>>////////////////////////////////////////////////////////////////
>>
>>All of the functions are properly set in name.cpp. Like so:
>>
>>////////////////////////////////////////////////////////////////
>>#include "main.h"
>>
>>Name::Name( void )
>>{
>><Code to init the names>
>>}
>>
>>Name::~Name( void )
>>{
>>}
>>
>>Name::full( void )
>>{
>>return( m_full );
>>}
>>
>>Name::human( long optA )
>>{
>><Code to create a human name>
>>}
>>
>>Name::elf( long optA )
>>{
>><Code to create an elven name>
>>}
>>///////////////////////////////////////////////////////////////////
>>
>>The "main.h" file contains all of the includes to the various
>>classes.
>>
>>///////////////////////////////////////////////////////////////////
>>#include <stdio.h>
>>#include <stdlib.h>
>>.
>>.
>>.
>>#include "name.h"
>>///////////////////////////////////////////////////////////////////
>>
>>Ok! Now that you have all of that information - here is the
>>question:
>>
>>When I compile - it likes everything. But when it reaches the
>>linker stage I get:
>>
>>Undefined Name::~Name()
>>Undefined Name::human( long optA )
>>Undefined Name::full()
>>
>>I've checked all of the functions. I've tried commenting out each
>>of the above one after the other - no other error messages are
>>coming out of the linker. Also, the first printf statement does
>>not give an error about gUC. So I know it is getting name.h
>>loaded.
>>
>>Why would the linker not like the functions themselves? Also,
>>under gcc this compiles without a problem (linux) but Borland C++
>>v5.02 dies. My next plan of attack is to delete and redo the
>>project's file. Maybe that is the answer. I recently decided to
>>move everything to a separate subfolder (called Character). So
>>maybe the project file is messed up somehow. Unknown but if you
>>have an idea I'd like to hear from you. ( XXXX@XXXXX.COM ).
>>
>>TIA to anyone who has an idea on this problem. :-)
 

Re:Re: Class problems

I did wait - for myself. As I posted later - I figured it out. It was
the project manager which was at fault.
Ed Mulroy [TeamB] wrote:
Quote
>void main( int argc, char *argv[] ) is perfectly valid as long as
>exit is not used.


void main is incorrect. The standards for the C and C++ languages
both specify that main is a function whose return type is int. There
is no relationship between this and the use of the function exit.
It may be incorrect but gcc, power c, borland C, borland C++, and
several others I have used do not complain. Thus, if the whole world
isn't complaining - how would someone know otherwise. Especially if the
books which came with these compilers have examples with void main()?
Me thinks thou dost protest too much.
Quote


>Now, if you would like me to send you the actual code ...


I wanted you to massage what you are using down to a stub of around 50
lines or less which compiles and which retains one or more of the
problems you are having and post that in a message.
Unfortunately, if you had read what I'd posted correctly, you would have
seen that I had said that the compilation worked without generating
errors. But that is the area you focused on. It was, I am afraid, the
wrong area.
Quote


>... I'd rather wait for someone else to help me. ...


Sounds like a good idea.
And as I said - I did. And I am very glad I did. Not that you could
not have given me insight into the problem. It is just that you were
pointed in the wrong direction. Thank you for your time. I shall
bother you no more.
Quote



>Mark Manning/Muniz Eng. wrote in message
>news: XXXX@XXXXX.COM ...
>Actually,
>
>void main( int argc, char *argv[] ) is perfectly valid as long as
>exit is not used. I misread my printout. So yes - it should be int
>with the exit command but I should have left off the exit command in
>my example.
>
>According to my book on C++ (as well as the several classes I've
>written, compiled, and run here at work not to mention the several
>courses I've had about C++) using void in a deconstructor is ok.
>You do not have to do that - but it can be done and it will have no
>bad side effects. Also, I've already tried removing the void within
>the deconstructor and the error remains. So I know that is not the
>problem.
>
>As for the quip "If you have a problem then post compilable source."
>If having to change one line in order to make it compile is too much
>for you then I'd rather wait for someone else to help me. Maybe
>they will focus on the problem at hand.
>
>Now, if you would like me to send you the actual code - I can do
>that and would be glad to do so. I can just create a zip file and
>send it to you of the entire directory structure as well as all of
>the source code files and project file (minus the object files and
>compiled program). Didn't want to post tons of pages so I posted
>what I thought (doing a single pass from the printout since I am at
>work presently) was a reasonable job of transferring the basic
>problem into this post. But if you would like to see the entire
>thing - I can send you that as well. Just give me an e-mail address
>to send it to and then give me about an hour or two because I first
>have to make it back home.
>
>Later.
>
>Ed Mulroy [TeamB] wrote:
>
>>Start by cleaning up the code.
>>
>>The function main returns an int. It does not return void.
>>
>>You exit from main with a return statement such as
>>return 0;
>>You do NOT exit from main by calling exit.
>>
>>C++ functions, including constructors and destructors, that take no
>>arguments have () and not (void).
>>
>>If you have a problem then post compilable source.
>>
>>. Ed
>>
>>
>>
>>>Mark Manning/Muniz Eng. wrote in message
>>>news:4143ab20$ XXXX@XXXXX.COM ...
>>>
>>>I recently got the Borland C++v5.02 compiler et al. I've done work
>>>with C++ for years but the compiler is frustrating me.
>>>
>>>I am making a simple "create a name" program for our D&D game and
>>>I've made a class called "Name". It looks like this:
>>>
>>>/////////////////////////////////////////////////////////////////
>>>enum { gUC, gLC }; // Upper and lowercase ENUMs
>>>enum { gMale, gFemale ); // Character's gender
>>>
>>>class Name
>>>{
>>>private:
>>><my variables>
>>>
>>>public:
>>>Name( void );
>>>~Name( void );
>>>
>>>full( void ); // Return the full name.
>>>human( long optA ); // Create a human name.
>>>elf( long optA ); // Create an elven name.
>>>};
>>>////////////////////////////////////////////////////////////////
>>>
>>>The main program looks like this:
>>>
>>>////////////////////////////////////////////////////////////////
>>>#include "main.h"
>>>
>>>void
>>>main( int argc, char *argv[] )
>>>{
>>>Name myName;
>>>
>>>printf( "gUC = %d\n", gUC );
>>>myName.human( gMale );
>>>printf( "My name is: %s\n", myName.full() );
>>>exit( 0 );
>>>}
>>>////////////////////////////////////////////////////////////////
>>>
>>>All of the functions are properly set in name.cpp. Like so:
>>>
>>>////////////////////////////////////////////////////////////////
>>>#include "main.h"
>>>
>>>Name::Name( void )
>>>{
>>><Code to init the names>
>>>}
>>>
>>>Name::~Name( void )
>>>{
>>>}
>>>
>>>Name::full( void )
>>>{
>>>return( m_full );
>>>}
>>>
>>>Name::human( long optA )
>>>{
>>><Code to create a human name>
>>>}
>>>
>>>Name::elf( long optA )
>>>{
>>><Code to create an elven name>
>>>}
>>>///////////////////////////////////////////////////////////////////
>>>
>>>The "main.h" file contains all of the includes to the various
>>>classes.
>>>
>>>///////////////////////////////////////////////////////////////////
>>>#include <stdio.h>
>>>#include <stdlib.h>
>>>.
>>>.
>>>.
>>>#include "name.h"
>>>///////////////////////////////////////////////////////////////////
>>>
>>>Ok! Now that you have all of that information - here is the
>>>question:
>>>
>>>When I compile - it likes everything. But when it reaches the
>>>linker stage I get:
>>>
>>>Undefined Name::~Name()
>>>Undefined Name::human( long optA )
>>>Undefined Name::full()
>>>
>>>I've checked all of the functions. I've tried commenting out each
>>>of the above one after the other - no other error messages are
>>>coming out of the linker. Also, the first printf statement does
>>>not give an error about gUC. So I know it is getting name.h
>>>loaded.
>>>
>>>Why would the linker not like the functions themselves? Also,
>>>under gcc this compiles without a problem (linux) but Borland C++
>>>v5.02 dies. My next plan of attack is to delete and redo the
>>>project's file. Maybe that is the answer. I recently decided to
>>>move everything to a separate subfolder (called Character). So
>>>maybe the project file is messed up somehow. Unknown but if you
>>>have an idea I'd like to hear from you. ( XXXX@XXXXX.COM ).
>>>
>>>TIA to anyone who has an idea on this problem. :-)



 

Re:Re: Class problems

This is correct. (That it doesn't make it any more correct.) But if the
whole world is doing one thing and the manual says another. Then which
is correct? I have (at last count) at least six C compilers and four
C++ compilers. (At least that is how many I have checked so far.) And
none of them give an error on this. Now, I haven't checked MetroWerk's
C compiler on the Mac yet and I haven't booted up Windows XP (I use DOS
6.22, Windows v3.1, 95, and 98se but I also have Windows NT, Me, and XP
I can try this on). Maybe one of them will say I can't do this but so
far - no problem.
Still, you are right - it doesn't make it any more correct. It's just -
doesn't make it any more wrong either. However, in honor of you
pointing this out - I have changed my program to reflect what you have
said is the correct method to use. I decided that if I am going to
write a program which will be used on a web server I might as well
return a status so the Perl script which calls it can determine whether
or not it terminated properly and since void doesn't return any kind of
a status that I'd use int instead. Only where I work they frown on
using int and insist on us using long for all return status'. Still,
int is better if you are compiling for 16bit operations and 32bit
operations because it usually switches depending upon which type of OS
you are using. :-)
Later! Found and fixed the error. Off to the next one. :-)
Mark
Thomas Maeder [TeamB] wrote:
Quote
"Mark Manning/Muniz Eng." <mark@glab>writes:


>void main( int argc, char *argv[] ) is perfectly valid as long as exit
>is not used.


No. Both the C and the C++ language have always required the return type
of main() to be int. The ISO Standards for the languages require compilers
to produce a diagnostic message if the return type is different from void.

There are many buggy compilers out there, including, I think all Borland
has ever released, that let you get away with main()'s return type being
void, but that doesn't make doing it any more correct.
 

Re:Re: Class problems

Well, I must ask for your indulgence on this long VERY duplicated post.
I've read the etiquette guides now and must apologize for the huge
duplication. If and when I post in the future (this is the first such
request in almost twenty years of using Turbo C because I switched to
Borland C++ v5.02). So it is highly unlikely that I will post again for
many years to come. Still, I should have read the etiquette guidelines
before posting.
Later!
Mark
Mark Manning wrote:
Quote
I did wait - for myself. As I posted later - I figured it out. It was
the project manager which was at fault.