public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: gcc template error?
@ 2005-06-22 19:31 Jason Mancini
  2005-06-22 19:41 ` Shelly Adhikari
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Mancini @ 2005-06-22 19:31 UTC (permalink / raw)
  To: gcc; +Cc: shelly

I suspect this line is the source of your problems:
   friend T<class Y>* func<Y, X>(T<X>* p);
Y isn't a template parameter here, but a (concrete?) class named "Y".
The below compiles with 3.4.3 anyways...
Regards,
-Jason


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


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


template <typename X, typename Y> class T;

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


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


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


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcc template error?
  2005-06-22 19:31 gcc template error? Jason Mancini
@ 2005-06-22 19:41 ` Shelly Adhikari
  0 siblings, 0 replies; 4+ messages in thread
From: Shelly Adhikari @ 2005-06-22 19:41 UTC (permalink / raw)
  To: Jason Mancini; +Cc: gcc

Jason Mancini wrote:

> I suspect this line is the source of your problems:
>   friend T<class Y>* func<Y, X>(T<X>* p);
> Y isn't a template parameter here, but a (concrete?) class named "Y".
> The below compiles with 3.4.3 anyways...
> Regards,
> -Jason

Yep, that line is the source of my problems.
Can you send me a pointer to the C++ standard which says what you are 
saying?
Two template parameters are not acceptable in my situation. I would have 
to find another solution.

Best Regards,
Shelly

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcc template error?
  2005-06-22 17:58 Shelly Adhikari
@ 2005-06-22 18:14 ` Andrew Pinski
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Pinski @ 2005-06-22 18:14 UTC (permalink / raw)
  To: Shelly Adhikari; +Cc: gcc


On Jun 22, 2005, at 1:56 PM, Shelly Adhikari wrote:

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

I don't know if this is valid C++ or not but on the mainline we ICE so 
I filed
PR 22147.

-- Pinski

^ permalink raw reply	[flat|nested] 4+ messages in thread

* gcc template error?
@ 2005-06-22 17:58 Shelly Adhikari
  2005-06-22 18:14 ` Andrew Pinski
  0 siblings, 1 reply; 4+ messages in thread
From: Shelly Adhikari @ 2005-06-22 17:58 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-06-22 19:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-22 19:31 gcc template error? Jason Mancini
2005-06-22 19:41 ` Shelly Adhikari
  -- strict thread matches above, loose matches on Subject: below --
2005-06-22 17:58 Shelly Adhikari
2005-06-22 18:14 ` Andrew Pinski

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