class template and type(def)

R

rogo

Hello folks,

I have a problem with the following code:

---

#include <boost/shared_ptr.hpp>

namespace communication
{
class Result
{
};
}

template <typename Concrete_Container>
class Result_Interpreter
{
public:

typedef ::boost::shared_ptr<Concrete_Container>
Data_Container_Pointer;
typedef ::communication::Result Result;

Data_Container_Pointer interpret_data(const Result& result);
private:
Result_Interpreter();
};

template <typename Concrete_Container>
Result_Interpreter<Concrete_Container>::Data_Container_Pointer
// error:
Result_Interpreter<Concrete_Container>::interpret_data(
const Result_Interpreter::Result& result)
{
Data_Container_Pointer data_container (new Concrete_Container());

return data_container;
}

int main()
{
return 0;
}

---

G++ says "expected constructor, destructor, or type conversion before
»Result_Interpreter«" in the line following "// error:". Could you
give me any pointers why it does not work and how it would? It's not a
pressing matter but I'd like to hide the pointer type (shared_ptr)
from the implementation.

Best Regards
Rogo
 
S

SG

Hello folks,

I have a problem with the following code:

[snip]

It seems your code lacks a "typename" right in fron of
"Result_Interpreter<Concrete_Container>::Data_Container_Pointer". The
compiler doesn't know that
"Result_Interpreter<Concrete_Container>::Data_Container_Pointer" is
supposed to be a type because it depends on the template parameter
"Concrete_Container".

Cheers!
SG
 
M

Michael DOUBEZ

rogo said:
I have a problem with the following code: [snip]
template <typename Concrete_Container>
class Result_Interpreter
{
public:

typedef ::boost::shared_ptr<Concrete_Container>
Data_Container_Pointer;
typedef ::communication::Result Result;

Data_Container_Pointer interpret_data(const Result& result);
private:
Result_Interpreter();
};

template <typename Concrete_Container>
Result_Interpreter<Concrete_Container>::Data_Container_Pointer

This is a dependent type, you must specify it is a type:
// error:
Result_Interpreter<Concrete_Container>::interpret_data(
const Result_Interpreter::Result& result)
{ [snip]
Could you
give me any pointers why it does not work and how it would?
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top