Barton-Nackman and compilation under Solaris

N

nguyenxuanson

Dear group readers,
I use the Barton-Nackman trick in my code, and I can compile it
correctly with Visual Studio 7.0 but have problem when trying to cmpile
Sun/Solaris Compiler C/C++. The problem comes from the following line
of code, the error is "multiple decoration for MYBASECLASS". I hope
that you have had a solution for the problem otherwise I will have to
recoding to remove the template.

class MYDERIVEDCLASS:public MYBASECLASS<MYDERIVEDCLASS> {
friend class MYBASECLASS;
}

Where I have define MYBASECLASS as:

template<typename ADerivedSolver> class MYBASECLASS{}


Hope to hear from you soon.
Regards,
Xuan Son
 
V

Victor Bazarov

I use the Barton-Nackman trick in my code, and I can compile it
correctly with Visual Studio 7.0 but have problem when trying to cmpile
Sun/Solaris Compiler C/C++.

First of all, have you read the FAQ? I think that section 5 is the most
relevant. If you have a problem with code, post the code. If you have
a problem with a particular compiler, post to that compiler newsgroup
before posting here.
> The problem comes from the following line
of code, the error is "multiple decoration for MYBASECLASS".

You mean "multiple _declaration_", for sure?
> I hope
that you have had a solution for the problem otherwise I will have to
recoding to remove the template.

class MYDERIVEDCLASS:public MYBASECLASS<MYDERIVEDCLASS> {
friend class MYBASECLASS;

'MYBASECLASS' here is not a class. MYBASECLASS<MYDERIVEDCLASS> is. You
need to change this to

friend class MYBASECLASS said:
}

Where I have define MYBASECLASS as:

template<typename ADerivedSolver> class MYBASECLASS{}

Instead of using English, use C++, it is easier to understand. Like this:
------------------------------ code

template<typename A> class MYBASECLASS {};
class MYDERIVEDCLASS:public MYBASECLASS<MYDERIVEDCLASS> {
friend class MYBASECLASS;
};

------------------------------ end code
Now, I can then take it as is and pass it through my compiler...

Anyway, you have your solution, I hope.

V
 
T

TB

(e-mail address removed) sade:
Dear group readers,
I use the Barton-Nackman trick in my code, and I can compile it
correctly with Visual Studio 7.0 but have problem when trying to cmpile
Sun/Solaris Compiler C/C++. The problem comes from the following line
of code, the error is "multiple decoration for MYBASECLASS". I hope
that you have had a solution for the problem otherwise I will have to
recoding to remove the template.

class MYDERIVEDCLASS:public MYBASECLASS<MYDERIVEDCLASS> {
friend class MYBASECLASS;
}

Where I have define MYBASECLASS as:

template<typename ADerivedSolver> class MYBASECLASS{}

I guess you didn't mean

#define MYBASECLASS template<typename ADerivedSolver> class MYBASECLASS{}

as I read it and thought "what the hell?" :)
 
V

Victor Bazarov

TB said:
(e-mail address removed) sade:



I guess you didn't mean

#define MYBASECLASS template<typename ADerivedSolver> class MYBASECLASS{}

as I read it and thought "what the hell?" :)

When people say "define a class" they rarely mean using the preprocessor
"define" directive. A definition of a class (or a class template) differs
from a declaration by the existence of the _body_. So, when the OP said
"I have define[d] BLAH as", the presence of the curly braces indicates
that it's a _definition_.

I can say, "I defined my 'foo' function as

void foo(int a) {
cout << a;
}
"

which is supposed to bring your attention to the _body_. Compare it to
what you'd be looking at/for if I said, "I declared my 'foo' function as

void foo(int);

". The body (and the side effects) are irrelevant.

HTH

V
 
T

TB

Victor Bazarov sade:
When people say "define a class" they rarely mean using the preprocessor
"define" directive. A definition of a class (or a class template) differs
<snip>

Actually he said "Where I have define MYBASECLASS as:" and when reading
the all-capital-letter name my mind accidently switched into
#define-context, so I became perplexed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top