[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: SV: SV: [CPROG] C++ spørgsmål - hvad gårgalt med minstring?



On Sun, 22 Apr 2001, Jonas Christian Drewsen wrote:

> >bliver. Altså, linkeren fejler i det første tilfælde, men ikke i det
> >andet.
> >
> >Med mindre navnet eller typedef gør en afgørende forskel, så må det vel
> >næsten være en fejl i g++, eller hvad? Eller har jeg bare stadig ikke
> >fattet noget?
> 
> Programmet nedenfor oversætter og kører fint, gør den også det for dig?:
> 

Ja, fordi der linkes jo ikke mellem filer. Men, split det op sådan her:

sub.hh
---------------
#include <string>
typedef struct {
  string AsString() const;
} ged_t;

class Ged {
public:

  string AsString() const;
};
----------------

sub.cc
----------------
#include "sub.hh"

string ged_t::AsString() const { return "a"; }

string Ged::AsString() const { return "b"; }
---------------


main.c
---------------
#include <iostream>
#include <string>
#include "sub.hh"

int main() {
  ged_t a1 = ged_t();
  Ged b1 = Ged();
  const ged_t a2 = ged_t();
  const Ged b2 = Ged();

  cout << "a " << a1.AsString() << a2.AsString() << endl;
  cout << "b " << b1.AsString() << b2.AsString() << endl;

  return 0;
}
----------------

Jeg håber vi er enige om at det er en OK opdeling?

Anyway, så får jeg:

sslug@sslug tmp]$ g++ -Wall -c sub.cc
sslug@sslug tmp]$ g++ -Wall -o main main.c sub.o
/tmp/ccHMpKYw.o: In function `main':
/tmp/ccHMpKYw.o(.text+0x2a): undefined reference to
`._24::AsString(void) const'/tmp/ccHMpKYw.o(.text+0x44): undefined
reference to `._24::AsString(void) const'collect2: ld returned 1 exit
status                                             

!

Ændrer jeg nu sub.hh til 

sub.hh
-----------------------
#include <string>
class ged_t {
public:
  string AsString() const;
};

class Ged {
public:

  string AsString() const;
};
---------------------

får jeg

sslug@sslug tmp]$ g++ -Wall -c sub.cc
sslug@sslug tmp]$ g++ -Wall -o main main.c sub.o
sslug@sslug tmp]$ ./main
a aa
b bb                                                                            

!

Der sker altså et eller andet for
sslug@sslug tmp]$ g++ -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)                                        

når man går fra en typedef struct til en class.

Tog mig lige lidt tid at finde ud af. Formentlig en bug i min compiler.

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
Before we'd usually say, there is a deep rumbling sound of penguins. Now
it's time to begin with: The earth is quaking, hell yeah the penguins are 
here!!



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *