www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/17/21:03:28

From: Sean Melody <s-melody AT STOP DOT SPAMMERS DOT nwu DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: C++ templates question
Date: Fri, 17 Apr 1998 17:11:46 -0500
Organization: Northwestern University, Evanston, IL, US
Lines: 77
Message-ID: <3537D3A2.A878B8DD@STOP.SPAMMERS.nwu.edu>
References: <19980417 DOT 7001502 AT seneca>
NNTP-Posting-Host: hin082083.res-hall.nwu.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

string.h is c strings
string is c ++ strings.
Try include <string>
Might work, might not.
schuster AT eev DOT e-technik DOT uni-erlangen DOT de wrote:
> 
> Hi !
> When writing some C++ code with djgpp, i've encountered the following
> problem with templates (I don't know if this is a bit off topic, but
> don't know if it's a general c++ question or a djgpp - c++ question
> either)
> Look at:
> 
> #include <string.h>
> template <class T> class test
> {
>    int a;
>    char r[34];
>  public:
>    test(int integ, char* string);
> };
> template <class T> test<T>::test(int integ, char* string)
> {
>    a=integ;
>    strcpy(string,r);
> }
> int main()
> {
>  test<int> Ttest(1,"S");
> }
> 
> this works fine, but when changing to the following, the linker says
> undefined reference to
> the constructor of class <T> test. (look at the position of test<int>
> Ttest(1,"S") )
> 
> #include <string.h>
> template <class T> class test
> {
>    int a;
>    char r[34];
>  public:
>    test(int integ, char* string);
> };
> template <class T> test<T>::test(int integ, char* string)
> {
>    a=integ;
>    strcpy(string,r);
> }
> test<int> Ttest(1,"S");
> int main()
> {
> 
> }
> 
> if I change it to the next all works fine. Any idea why. Is this
> normal or djgpp - c++ spezific?
> Thanks
> Michi
> 
> #include <string.h>
> template <class T> class test
> {
>    int a;
>    char r[34];
>  public:
>    test(int integ, char* string){
>    a=integ;
>    strcpy(string,r);
>    }
> 
> };
> test<int> Ttest(1,"S");
> int main()
> {
> 
> }

- Raw text -


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