[lug] search and replace

Mike Vigorita viggy at commerce.com
Tue Dec 28 09:28:10 MST 1999


First, get a good beginner book.  Unfortunately, I don't have the title of
one, but I'm sure that others can suggest one.

To declare a class in C++:

In the header file (".h"):
-----------------------------------
class foo
{
  public:
    int var1;
    int var2;

    # Constructor
    foo ();

    void Function1 ( {params} );
    int Function2 ( {params} );

  protected:
    int protVar1;
    int protVar2;

    float protFunc1 ( {params} );

  private:
    float privVar1;

    void privFunc1 ();
};

Now, in the cpp file, define the functions above!
--------------------------------------------------
void foo::foo()
{
  #Constructor stuff here...
}

void foo::Function1 ( ... )
{
}

...

float foo::protFunc1 ( ...)
{
}

------------------------------------------------

You do not need to define any of the classes/functions with "extern ..."
unless you plan on calling the C++ functions from a C program.  C++ mangles
function/classnames differently than C, so if you want to use C++ functions
in C, then you must enclose those functions in a 'extern "C"' block (in the
header file):

extern "C"
{
  # Define classes/functions here!
}

Viggy


> -----Original Message-----
> From: lug-admin at lug.boulder.co.us [mailto:lug-admin at lug.boulder.co.us]On
> Behalf Of Chan Kar Heng
> Sent: Tuesday, December 28, 1999 9:07 AM
> To: lug at lug.boulder.co.us
> Subject: Re: [lug] search and replace
>
>
> hi.
>
> rather off topic question here... sorry for inconveniences, but it was
> rather urgent.
>
> i'm sorta new to c++... been wondering how i can do the following with
> c++. tried looking around, but didn't really find any sort of
> documentation for this..
>
> in typical c, to do the following:
>
> gcc mylib.c -o mylib.o
> gcc mylib2.c -o mylib2.o
> gcc mylib.o my.ib2.o main.c -o main
>
> i make mylib.h, mylib2.h and declare functions in mylib.c and mylib2.c
> using extern.. something like:
>
> extern int myfunc(void);
>
> how about in c++? how do i declare a class? i mean, i can't do this right?
>
> extern class MyString
> {
>   ...
> };
>
> i tried compiling another way (where i just extracted the class
> declarations
> and placed them in a .hpp file which was included by both other files) a
> "simple" class earlier and it retuned this:
>
> $ gcc n.o ntry.o -o ntry.exe
> ntry.o(.text+0x125):ntry.cpp: undefined reference to
> `operator==(Names &, Names &)'
> ntry.o(.text+0x173):ntry.cpp: undefined reference to
> `operator==(Names &, Names &)'
> ntry.o(.text+0x1c1):ntry.cpp: undefined reference to
> `operator==(Names &, Names &)'
>
>
> thanks in advance.
>
> ps: happy new year!! 8-)
>
>
>
>
> --------------------------------------------
> i don't suffer from stress... i'm a carrier.
> http://home.backroom.net/~bozo
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
>
>






More information about the LUG mailing list