🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #915

Re: how can i tell if my new c++ compiler is working?

#915
From: Andy J Robb
Date: Tue, 05 Sep 1995 04:32
64 lines
2317 bytes
bcc063@casbah.acns.nwu.edu (UNLISTED) wrote:

>i just finished installing the libg++ library for c++ and i want to test the
>compiler to see if it is working. when i try to compile the following little
>test file using gcc,
>i get these errors:
>	collect2: ld returned 2 exit status
>	ld: Undefined symbol
>	  String::length(void)
>	  String::set_to(char *)
>	  String::read(void)

>what do these errors mean i did or didn't do? 
>(i'm new at c++)
>below are the files...

>/* this is the beginning of file String.h */
>const int max_string_length = 128;
>class String{
>public:
>  void set_to(char*);
>  int length();
>  int read();
>  void print();

>private:
>  char text[max_string_length+1];
>};
>/* this is the end of file String.h */

You have only "declared" the member functions, set_to, length, read
and printf.  You must "define" them as well.  If they are simple (one
liners) then this can be done within the class instead of the
declarations. . .

#include <stdio.h>
#include <string.h>

class String
{ char text[max_string_length+1);

public:
  void set_to(char *str) { strncpy(text, str, sizeof text); }
  int length() { return strlen(text); }
  void read() { gets(text); }
  void printf() { puts(text); }
};

Simple member functions like these are implicitly "inline" so they
incur no overhead above directly accessing a structure member in C.

Regards,
Andy Robb.

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2i

mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
=/wVD
-----END PGP PUBLIC KEY BLOCK-----
Technical Details
Message-ID: <42gjrm$80b@fitzherbert.pavilion.co.uk>
Path: arc1-ca.pugleaf.net!news.pavilion.co.uk!usenet
References: <42fktm$g2p@news.acns.nwu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.pavilion.co.uk!usenet
From: AJRobb@pavilion.co.uk (Andy J Robb)
Newsgroups: gnu.gcc.help,comp.lang.c++,comp.unix.programmer
Subject: Re: how can i tell if my new c++ compiler is working?
Date: Tue, 05 Sep 1995 04:32:13 GMT
Organization: Pavilion Internet plc, Brighton, England
Message-ID: <42gjrm$80b@fitzherbert.pavilion.co.uk>
References: <42fktm$g2p@news.acns.nwu.edu>
NNTP-Posting-Host: line02.gunn-du.pavilion.co.uk
X-Newsreader: Forte Free Agent 1.0.82