Barton-Nackman and compilation under Solaris

Discussion in 'C++' started by nguyenxuanson@gmail.com, Jan 17, 2006.

  1. Guest

    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
     
    , Jan 17, 2006
    #1
    1. Advertising

  2. wrote:
    > 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<MYDERIVEDCLASS>;

    > }
    >
    > 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
     
    Victor Bazarov, Jan 17, 2006
    #2
    1. Advertising

  3. TB Guest

    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?" :)

    --
    TB @ SWEDEN
     
    TB, Jan 17, 2006
    #3
  4. TB wrote:
    > 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?" :)
    >


    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
     
    Victor Bazarov, Jan 17, 2006
    #4
  5. TB Guest

    Victor Bazarov sade:
    > TB wrote:
    >> 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?" :)
    >>

    >
    > 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.

    --
    TB @ SWEDEN
     
    TB, Jan 17, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Glavitsch

    java font selection under solaris 8

    Michael Glavitsch, Jul 15, 2003, in forum: Java
    Replies:
    1
    Views:
    479
    Roedy Green
    Jul 15, 2003
  2. Michael Lehn

    Problems with "Barton Nackman Trick"

    Michael Lehn, Jan 11, 2005, in forum: C++
    Replies:
    2
    Views:
    539
    Michael Lehn
    Jan 15, 2005
  3. Behrang Dadsetan

    Waiting for processes to finish under Solaris

    Behrang Dadsetan, Jul 15, 2003, in forum: Python
    Replies:
    1
    Views:
    549
    Behrang Dadsetan
    Jul 15, 2003
  4. Ish Aden
    Replies:
    3
    Views:
    367
    Ish Aden
    Sep 11, 2007
  5. krishu

    Tk Compilation on Solaris 10 Failing

    krishu, Dec 4, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    177
    krishu
    Dec 5, 2007
Loading...

Share This Page