delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/06/21:44:28

Message-Id: <3.0.6.32.19990206214250.008dee10@pop.netaddress.com>
X-Sender: pderbysh AT pop DOT netaddress DOT com
X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32)
Date: Sat, 06 Feb 1999 21:42:50 -0500
To: djgpp AT delorie DOT com
From: Paul Derbyshire <pderbysh AT usa DOT net>
Subject: Re: template support in v 2.02
In-Reply-To: <36BCF05D.727BBEDF@a.crl.com>
References: <36BCCD3E DOT 23E88D5 AT bignet DOT net>
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

At 07:46 PM 2/6/99 -0600, you wrote:
>I suspect that v2.02 (which uses G++ 2.8.x?) would support templates
>more than v2.01.  But understand that the ANSI C++ standard was adapted
>only a little more than a year ago, it is possible that not all of the
>standard features are supported in the current implementation.

Yeah. Just try to compile and link anything that has 2 sourcefiles that
include the following header and use the template in it. Make each source
file refers to one of foo::foo(), foo:set_default(const T &), or
foo::set_default().

// linktst.h

template <class T> class foo {
public:
  foo (const T &x) : my_t(x) { }
  foo (void) : my_t(default_t) { }
  ~foo (void) { }
  void set_default (const T &x) { default_t = x; }
  void set_default (void) { default_t = my_t; }
  t &get_t (void) { return my_t; }
  const t &get_t (void) const { return my_t; }
  void set_t (const T &x) { my_t=x; }
private:
  static T default_t;
  T my_t;
}


>I tried to compile:
>===============================================
>/* junk.cc */
>void main()
>{
>}
>===============================================
>
>with the command line
>===============================================
>gxx -Wall junk.cc
>===============================================
>
>and got the following error
>=================================================================
>junk.cc:2: warning: return type of 'main' changed to integer type
>=================================================================
>
>What's going on?

C allowed you to use "void main()" though it was bad practise and led to
undefined behavior with regard to the error level returned.
C++ doesn't like "void main" at all. "int main" is the only way to comply
with the standard. int main(void), int main(int argc, char **argv) and int
main(int argc, char**argv, char**env) are the only legitimate prototypes
for main IIRC.

And before you do something like

int main (void) {
  cout << "Hello world!";
}

and complain about the warning that produces, C++ also expects something to
be returned from main. When in doubt, "return 0;" from main.

-- 
   .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
-()  <  circles, and bark is not smooth, nor does lightning travel in a
   `*'  straight line."    -------------------------------------------------
        -- B. Mandelbrot  |http://surf.to/pgd.net
_____________________ ____|________     Paul Derbyshire     pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019