Group: comp.lang.c++
From: "sk_usenet"
Date: Saturday, April 12, 2008 6:10 PM
Subject: Re: Class prototype vs C function prototype


"June Lee" wrote in message
> Is that for Class/Object function prototype, I must define the
> function in header file or .cpp file.
>
> MyClass::functionA();
> MyClass::functionB();

These are not definitions.

> but for C function prototype, I don't have to define if it's put
> before the main() function the following is not needed -
>
> void stradd (char *s1, char *s2);
> void stradd (char *s1, int i);

These are not definitions either. These are declarations. Compiler must know
about your function before you call them (through an appropriate
declaration/definition).

> =========
> #include // cannot be iostream.h??

Yes, no iostream.h. That's non standard.

> #include
> #include
>
>
> #include
> #include
> #include // must need for SYSTEMTIME

Non standard.

> //must need C/C++ > General > Debug Information Format to debug
> working
>
> using namespace std; // for cout must have??

Yes. Else reference cout as std::cout.

> // concatenate two strings
> void stradd (char *s1, char *s2)
> {
> strcat (s1, s2); // CRT function
> }
>
> // concatenate a string with a "stringized" integer
> void stradd (char *s1, int i)
> {
> char temp[80];
>
> sprintf (temp, "%d", i);
> strcat (s1, temp);
> }
Do some error checking in your code. Like what happens when s1 is not big
enough to accomodate temp?

>
>
> int main()
> {
> //SYSTEMTIME st = {0,0,0,0,0,0,0,0}; // cannot divide into 2
> lines - must init all in one line
> SYSTEMTIME st = {0}; // OK too
>
> char str[80];
> //char* str; // not OK will crash program

Right. Modifying a string literal is undefined behavior.

> strcpy (str, "Hello ");
> stradd (str, "there");
> cout << str << "\n";
>
> stradd (str, 100);
> cout << str << "\n";
>
> stradd (str, "hihi");
> cout << str << "\n";
>
> return 0;
> }

HTH
--
http://techytalk.googlepages.com