static function template problem on sun compiler

S

SC Shin

Hi, everyone

I've got problem.
I am able to compile following code without error on Compaq, Linux machine
But I am not able to compile this with error on Sun with forte7 compiler:
line 26: Unexpected type name: Apple

Please carefully review following code
And Let me know what problem is and how to solve this problem

1 class Apple
2 {
3 public:
4 static int load();
5 };
6
7 class Banana
8 {
9 public:
10 template<typename EL>
11 void load()
12 {
13 m_banana = EL::load();
14 }
15
16 private:
17 int m_banana;
18 };
19
20 class Peach
21 {
22 public:
23 static void initialize()
24 {
25 m_this = new Peach();
26 m_this->o_banana.load<Apple>();
27 }
28 static Peach* m_this;
29
30 private:
31 Banana o_banana;
32 };
33
34 Peach* Peach::m_this;
35
36 int main()
37 {
38 return 0;
39 }
 
W

WW

SC said:
Hi, everyone

I've got problem.
I am able to compile following code without error on Compaq, Linux
machine But I am not able to compile this with error on Sun with
forte7 compiler: line 26: Unexpected type name: Apple

Please carefully review following code
And Let me know what problem is and how to solve this problem

Cut the line numbers please! You do not refer to them and if the others do
not top post, they don't need to either. But it is impossible to copy paste
and try your code. As for the problem: I might be mistaking (due to the
disturbing line numbers I did not read it all) what you have is what I have
seen already several times myself with Sun compiler. It has something
against member templates, whenever you want to access them via a reference
(be it reference or pointer).
 
C

Chris Theis

SC Shin said:
Hi, everyone

I've got problem.
I am able to compile following code without error on Compaq, Linux machine
But I am not able to compile this with error on Sun with forte7 compiler:
line 26: Unexpected type name: Apple

Please carefully review following code
And Let me know what problem is and how to solve this problem
[SNIP]

You should consider changing your compiler - I've experienced similar
problems with this compiler handling templates. I'm not sure because I
haven't used Sun for a long time but there should be a decent GNU compiler
or some other product available.

regards
Chris
 
D

dslater

try changing:

template<typename EL>
void load()
{
m_banana = EL::load();
}

to

template <typename EL>
void load(const EL *unused=0)
{
m_banana = EL::load();
}


I know that on the Microsoft compiler, a function template must use
all of the template parameters in the argument list. Perhaps the
forte7 compiler has the same limitation.
 
S

SC Shin

WW said:
Cut the line numbers please! You do not refer to them and if the others do
not top post, they don't need to either. But it is impossible to copy paste
and try your code. As for the problem: I might be mistaking (due to the
disturbing line numbers I did not read it all) what you have is what I have
seen already several times myself with Sun compiler. It has something
against member templates, whenever you want to access them via a reference
(be it reference or pointer).

Thanks WW

Please compile following code and let me know how to solve this problem

class Apple
{
public:
static int load();
};

class Banana
{
public:
template<typename EL>
void load()
{
m_banana = EL::load();
}

private:
int m_banana;
};

class Peach
{
public:
static void initialize()
{
m_this = new Peach();
m_this->o_banana.load<Apple>();
}
static Peach* m_this;

private:
Banana o_banana;
};

Peach* Peach::m_this;


int main()
{
return 0;
}
 
S

SC Shin

Thanks for your reply.

But changing code is still same problem on both forte7 and Microsoft compiler

Anaway thanks ^^
 
W

WW

SC Shin wrote:
[SNIP]
Please compile following code and let me know how to solve this
problem
[SNIP]

All I can tell you is what I have told you before. This is an error in the
compiler. I have no idea how can you solve it. When I have met something
similar the only solution was to call the member template on a full object,
not a pointer or a reference or an array element etc. My compiler compiles
it. You may try to put in the template keyword there (it must not be there,
but I have seen compilers requring it), but that might not help:

m_this->o_banana.template load<Apple>();

Must not be there, since neither peach, nor banana, nor the initialize
function is a template... but you can give it a try.
 

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,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top