C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with Sun CC. Class derived from template.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Mike Uchitelev
Guest





PostPosted: Mon Nov 29, 2004 9:49 pm    Post subject: Problem with Sun CC. Class derived from template. Reply with quote



Hello everyone,

i'm experiencing a weird problem while compiling/linking the following
piece of code in Sun CC compiler.

-------------- f1.h file -------------
class C{};
template < class T >
class A{};

class B : public A<C>
{
public: void f1();
};

------------ f1.cpp file -------------

void B::func1(){}
----------- another main cpp file -------
#include "f1.h"

int main(...)
{
B b;
b.f1();
}

When I try to compile everything gets compiled fine. When I try to
link, i always get errors that func1() has been determined many times,
which is certainly true, but doesn't change the original intention.

The workaround, I see now, is to put an implementation to the .h-file.
This is quite awkward, but it works. It's interesting to mention that
the code gets ported from VC++, where it has been compiled/linked
properly.

Does anybody know how to get it linked smoothly without putting
everything in one place?

I'd appreciate any helpful input,
Kind regards to all,
Mike Uchitelev.

Munich, Germany.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Daniel Krügler (ne Spange
Guest





PostPosted: Tue Nov 30, 2004 10:03 pm    Post subject: Re: Problem with Sun CC. Class derived from template. Reply with quote



Good morning Mike Uchitelev,

Mike Uchitelev schrieb:

Quote:
i'm experiencing a weird problem while compiling/linking the following
piece of code in Sun CC compiler.

-------------- f1.h file -------------
class C{};
template < class T
class A{};

class B : public A {
public: void f1();
};

------------ f1.cpp file -------------

Missing #include here:


#include "f1.h"


Quote:
void B::func1(){}

It was a long day, I assume;-)


You try to define here a member function func1, which was never declared
in your class. What about the alternative definition:

void B::f1(){}

?

Quote:
----------- another main cpp file -------
#include "f1.h"

int main(...)
{
B b;
b.f1();
}

When I try to compile everything gets compiled fine.

That is interesting, because the compiler should not accept you code in

f1.cpp.

Quote:
When I try to
link, i always get errors that func1() has been determined many times,
which is certainly true, but doesn't change the original intention.

Hmmh, are you sure, that you did not do any copy-paste-errors for this

posting? How do
you expect **multiple** definitions of func1??

Did you probably provide the definition of B::f1 (and not the not
existing B::func1) in the
header **without** inline specifier (but written as out-of-class
definition)??

Greetings from Bremen,

Daniel Krügler





[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Mike Uchitelev
Guest





PostPosted: Wed Dec 01, 2004 2:29 pm    Post subject: Re: Problem with Sun CC. Class derived from template. Reply with quote



Dear Daniel Krügler,

"Daniel Krügler (ne Spangenberg)" <dsp (AT) bdal (DOT) de> wrote

Quote:
Good morning Mike Uchitelev,

Mike Uchitelev schrieb:

i'm experiencing a weird problem while compiling/linking the following
piece of code in Sun CC compiler.

-------------- f1.h file -------------
class C{};
template < class T
class A{};

class B : public A {
public: void f1();
};

------------ f1.cpp file -------------

Missing #include here:

#include "f1.h"

There is a slight difference between so-called pseudo-code and the
real implementation. I presume you certainly know what it is. ;)

Quote:


void B::func1(){}

It was a long day, I assume;-)

Would you mind receiving the next time the source code as a .zip file
in size of just 2,5 Mb? Smile)))

Quote:

You try to define here a member function func1, which was never declared
in your class. What about the alternative definition:

void B::f1(){}

?

Perfect catch! This was a typo, I presume. :)

[The rest of message successfully skipped] Editorial of Mike Uchitelev
(c) certainly with the kind permission of Daniel Krügler... Smile))

To make long story short: the problem was in the wrong structuring of
the source code - Huge thanks to Stephen Clamage from California (I'm
awfully sorry, but Bremen to be mentioned hopefully next time). The
real solution is to put implementation of B into the separate file.
This peculiarity I wouldn't expect, since Visual C++ doesn't recognize
it as a problem.

Good to know!

Greetings to Bremen from Munich,

Mike.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.