public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Shelly Adhikari <shelly@interrasystems.com>
To: gcc@gcc.gnu.org
Subject: gcc template error?
Date: Wed, 22 Jun 2005 17:58:00 -0000	[thread overview]
Message-ID: <42B9A65A.3030403@InterraSystems.com> (raw)

Hello Guys,

Thw following program is giving an error. Is the program incorrect (If 
possible, please cite relevant sections from the C++ standard)? Should I 
file a bug?

% /usr/local/gcc-4.0.0/bin/g++ template.cxx
template.cxx: In function 'T<X>* func(T<Y>*) [with X = B, Y = A]':
template.cxx:36:   instantiated from here
template.cxx:21: error: 'A* T<A>::m_' is private
template.cxx:30: error: within this context

// Line 1
class A {
public:
    A() { };
    ~A() { };
};

class B {
public:
    B();
    B(const A& a) { };
    ~B();
};

template <typename X> class T;

template <typename X, typename Y>
T<X>* func(T<Y>* p);

template <typename X> class T {
    X*    m_;
public:
    T(X* x) : m_(x) { };
    ~T() { };
    friend T<class Y>* func<Y, X>(T<X>* p);
};

template <typename X, typename Y>
T<X>* func(T<Y>* p) {
    return (new T<X>(new X(*p->m_)));
}

int main() {
    A* a = new A();
    T<A>*    p = new T<A>(a);
    T<B>*    q = func<B, A>(p);
    return 0;
}

Best Regards,
Shelly

             reply	other threads:[~2005-06-22 17:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-22 17:58 Shelly Adhikari [this message]
2005-06-22 18:14 ` Andrew Pinski
2005-06-22 19:31 Jason Mancini
2005-06-22 19:41 ` Shelly Adhikari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42B9A65A.3030403@InterraSystems.com \
    --to=shelly@interrasystems.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).