473,503 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubt regarding structure nesting

Consider this:

template<typename T_fp>class TRigidBody : public BaseObject
{
public:
Jul 23 '05 #1
3 1130
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
2288
by: K.M. Jr. | last post by:
Hi all, Consider this line - char s = "\0"; Does this initialize all array elements to zero ? Thanks.
19
4222
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
77
3953
by: M.B | last post by:
Guys, Need some of your opinion on an oft beaten track We have an option of using "goto" in C language, but most testbooks (even K&R) advice against use of it. My personal experience was that...
8
2008
by: a | last post by:
I'm trying to save data from a custom object into the profile object, but it is not structured the way that I want. I'm trying to get the custom object to serialize as xml to a Profile object...
6
2059
by: shan | last post by:
I used the following code in linked list in C. typedef struct node { int data; struct node *next; //more explanation needed for this line }sll; Is *next a variable to struct node,If...
122
4158
by: ivan | last post by:
hi all, if I have: if(A && B || C) which operation gets executed first? If I remeber well should be &&, am I correct? thanks
1
2310
by: 4Ankit | last post by:
Hey guys i am having some trouble with nesting one selection structure within another selection structure. At the moment i am unclear what selection structures are and just need a simple example of...
2
2308
by: SandyIsCool | last post by:
Hi I used the below code for an image button image1.imageurl="~/images/image1.jpg"; image1.imageurl=Page.ResolveUrl("~/images/image1.jpg"); Both statements work fine..
12
5789
by: Steve | last post by:
I have been studying the Adjacency List Model as a means of achieving a folder structure in a project I am working on. Started with the excellent article by Gijs Van Tulder ...
8
2018
by: somenath | last post by:
Hi All, I have a doubt regarding the pointer assignment . Please have a look at the following program . #include<stdio.h> #include<stdlib.h> #define NAMESIZE 10 #define SAFE_FREE(t) if(t)\...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.