By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

Doubt regarding structure nesting

P: n/a
Consider this:

template<typename T_fp>class TRigidBody : public BaseObject
{
public:
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"darkstorm" <ma**********@hotmail.com> wrote in message
news:9b*************************@posting.google.co m...
Consider this:

template<typename T_fp>class TRigidBody : public BaseObject
{
public:
.
.
//member functions
.
.
//Current state of the rigid body

typedef struct TRB_state
{
RB_state(){}
TRB_state(){}

//data members

}RB_state;

inline RB_state GetRBState(uint8 state_id) const;

private:
//data members of rigidbody
///<Current state of the rigid body
RB_state m_state[2];
};

template<typename T_fp>
(error)----->inline TRigidBody<T_fp>::RB_state
TRigidBody<T_fp>::GetRBState(uint8 state_id) const
{
return m_state[state_id];
}

When compiling I am getting this error:
error C2143: syntax error : missing ';' before
'TRigidBody<T_fp>::GetRBState'

Somebody please explain it...


After making a number of changes to eliminate other errors (i.e., struct
constructor name, BaseObject, uint8), this compiled with no error in VC++
6.0. However, VS .NET 2003 gave the error that you reported, after first
giving this warning:
warning C4346: 'TRigidBody<T_fp>::RB_state' : dependent name is not a type
prefix with 'typename' to indicate a type

I can't explain the error, but I found that if I made the code a
non-template it compiled. It also compiled if the function body was placed
inside the class definition.

BTW, you don't need a typedef for the struct. That's a C-ism. You can just
use the struct name.

DW
Jul 23 '05 #2

P: n/a
Thanks for the reply. I couldn't make it compile that way. Instead of
returning a refernce to RB_state, I tried passing it as a reference
parameter. Then it worked fine.

template<typename T_fp>
inline void TRigidBody<T_fp>::GetRBState(RB_state &state, uint8
state_id) const
{
state = m_state[state_id];
}

although, I have to copyback once the modification is complete....
Jul 23 '05 #3

P: n/a
darkstorm wrote:
Thanks for the reply. I couldn't make it compile that way. Instead of
returning a refernce to RB_state, I tried passing it as a reference
parameter. Then it worked fine.

template<typename T_fp>
inline void TRigidBody<T_fp>::GetRBState(RB_state &state, uint8
state_id) const
{
state = m_state[state_id];
}

although, I have to copyback once the modification is complete....


Try

template<typename T_fp>
typename TRigidBody<T_fp>::RB_State
TRigidBody<T_fp>::GetRBState(...)
{
// ...
}

the "typename" is required to help out the parser tell the difference
between dependent types and members, before the template instantiation
is available to infer it.

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.