473,652 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubt regarding structure nesting

Consider this:

template<typena me T_fp>class TRigidBody : public BaseObject
{
public:
Jul 23 '05 #1
3 1140
"darkstorm" <ma**********@h otmail.com> wrote in message
news:9b******** *************** **@posting.goog le.com...
Consider this:

template<typena me 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(uint 8 state_id) const;

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

template<typena me T_fp>
(error)----->inline TRigidBody<T_fp >::RB_state
TRigidBody<T_fp >::GetRBState(u int8 state_id) const
{
return m_state[state_id];
}

When compiling I am getting this error:
error C2143: syntax error : missing ';' before
'TRigidBody<T_f p>::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_f p>::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<typena me T_fp>
inline void TRigidBody<T_fp >::GetRBState(R B_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<typena me T_fp>
inline void TRigidBody<T_fp >::GetRBState(R B_state &state, uint8
state_id) const
{
state = m_state[state_id];
}

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


Try

template<typena me 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
2304
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
4245
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 char* formatter, ...); Then, I want to call it as so:
77
3998
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 goto sometimes makes program some more cleaner and easy to understand and also quite useful (in error handling cases). So why goto is outlawed from civilized c programmers community. is there any technical inefficiency in that.
8
2017
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 like so: <Teachers> <Teacher> <Classes> <Class>
6
2068
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 yes then why it is not given
122
4236
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
2319
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 a selection structure within another selection structure. I am supposed to use function definitions with parameters to validate a form. my code for what i have done so far is as follows(cropped): function mainFunction() { var dateFormat =...
2
2316
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
5807
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 http://www.sitepoint.com/article/hierarchical-data-database My database has this basic structure: Id FolderName
8
2038
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
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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 we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.