|
Saying "struct container" is redundant as a struct is a container of (different) data types.
That aside, I'm not sure what you are asking. Your RFMAccess class has a TSimHeader structure in it with 10 instances defined. In order to access any one instance, you'll need to use square brackets like you've shown. It makes no difference whether you use TSimHeader_arr[i], or s[i].
Here's a kludgy example:
class MyOtherClass
{
struct RFMAccess::TSimHeader *ts;
void foo( int x )
{
ts = &(RFMAccess::TSimHeader_arr[x]);
}
};
You could also add the following function to your RFMAccess class:
static struct TSimHeader *GetSingleInstance( int x )
{
return (&TSimHeader_arr[x]);
}
And use it in another class like:
void foo2( void )
{
struct RFMAccess::TSimHeader *ts;
ts = RFMAccess::GetSingleInstance(0);
}
Notice that qualification is still necessary for both usages.
|
|
|
|
|
OK I see what you are saying,
Thanks,
steven
|
|
|
|
|
I was reading that a function always requires a return, but I don't see one for the statement below. I've posted the entire program below also. Thanks.
(cin>>x).get();
----------------------------------------------------------
#include "iostream.h"
#include "string.h"
int main()
{
int x;
int i;
char str[80];
bool isfinished=false;
char Info [] [300] =
{
"3030-02-000-5287" , "Here is the information for this number." ,
"3030-03-000-0029" , "Here is the information for this number." ,
};
while(isfinished==false)
{
cout<<"\nPlease enter a number:\n";
cin>>str;
for(i=0; i < 4; i += 2)
if(!strcmp(str, Info[i]))
{
cout<<"\nInformation:"<<info[i+1]<<"\n";
break;
="" }
="" if(i="=" 4)
="" {
="" cout<<"number="" not="" found.\n";
=""
="" cout<<"\nwould="" you="" like="" to="" check="" another?\n";
="" cout<<"enter="" 1="" for="" yes,="" 0="" no.\n";
="" (cin="">>x).get();//no return?
}
if (x==0) isfinished=true;
}
return 0;
}
|
|
|
|
|
DaveE9th wrote:
(cin>>x).get();//no return?
It appears to be a typo (or I am wrong). It should either be:
cin >> x;
or
int x = cin.get();
-Nick Parker
|
|
|
|
|
DaveE9th wrote:
if (x==0) isfinished=true;
This is incorrect. It should be
if (x == '0') isfinished=true;
John
|
|
|
|
|
(cin>>x).get() is a confusing way of writing:
cin >> x;<br />
cin.get();
The >> opertor returns a reference to the stream, so you can call the get() method on the return value.
--Mike--
"I'm working really, really fast at the moment, so a 3 minute outage becomes, due to time dilation, a 5 minute outage."
-- Chris Maunder, relativistic system administrator
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Interesting, I thought it looked like a typo.
Learn something new every day.
-Nick Parker
|
|
|
|
|
I still don't quite understand why function "get();" doesn't need a return. Why is this?
Thanks, Dave
|
|
|
|
|
The get() function with no parameters reads and returns the next character from the stream. If this character is not required (eg. you simply need to skip to the next character) then there is no use for the return value.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I read that if a function did not return a value that (at a minimum) you had to use the "void" prototype...such as below:
void main( )
no?
hmmmmm
Dave
|
|
|
|
|
The get() function returns a value - the value of the next character read. This program simply doesn't use the returned value.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thanks Ryan
"The man who reads nothing is better educated than the man who reads nothing but
newspapers."- Thomas Jefferson
|
|
|
|
|
is there an implementation of btrees in STL?
|
|
|
|
|
Are you referring to a binary tree structure? If yes, STL containers including set and map are designed using binary stree structure.
Kuphryn
|
|
|
|
|
By btree, do you mean a binary tree, which can be lopsided, or a B-tree, which is always balanced?
|
|
|
|
|
a balanced tree that is.
however, any kind of a tree I guess wouldn't be bad. Anything like CTreeCtrl in MFC even?
|
|
|
|
|
B-tree, red/black tree, splay tree, and AVL tree are all examples of balanced trees, each with their own set of nuances.
The CTreeCtrl class is for displaying a hierarchical list of items, much like Windows Explorer.
|
|
|
|
|
B-Tree?[^]
Not that I know of, and I've been searching for it for quite a bit.
|
|
|
|
|
I want to be able to allow the user to modify the numbers in the array of the working program below. I want to enable the user to have the ability to delete, change or add a new number into the array. What would be my best approach to do this? Thanks much, Dave
-------------------------------------------------------------------
#include "iostream.h"
#include "string.h"
int main()
{
int x;
int i;
char str[80];
bool isfinished=false;
char Info [] [300] =
{
"6787-02-000-5287" , "Here is the information for this number." ,
"5978-03-000-0029" , "Here is the information for this number." ,
};
while(isfinished==false)
{
cout<<"\nPlease enter a number:\n";
cin>>str;
for(i=0; i < 4; i += 2)
if(!strcmp(str, Info[i]))
{
cout<<"\nInformation:"<<info[i+1]<<"\n";
break;=""
}=""
if(i="=" 4)=""
{=""
cout<<"number="" not="" found.\n";=""
cout<<"\nwould="" you="" like="" to="" check="" another?\n";=""
{=""
cout<<"enter="" 1="" for="" yes,="" 0="" no.\n";=""
(cin="">>x).get();
}
if (x==0) isfinished=true;
}
return 0;
}
|
|
|
|
|
One solution is and STL list container.
Kuphryn
|
|
|
|
|
It depends on what you are after. As I understand it, you'd want a simply menu like:
CHOICES
----------
1. Display
2. Delete
3. Change
4. Add
If the user chose #1, you'd print the current contents of the array using code similar to what you've shown.
If the user chose #2, you'd prompt for the array index to delete. All items in the array after that index would probably need to be moved "up" in the order to fill in the hole.
If the user chose #3, you'd again prompt for: 1) the array index, 2) the part number, and 3) the part number description. The array item at the specified index would then be updated with these new values.
If the user chose #4, you'd prompt for the part number and the part number description. These values would then be assigned to the next available index.
|
|
|
|
|
I'll read up some more on arrays and the STL list container and maybe something will start smokin' up in my attic.
Thanks, Dave
|
|
|
|
|
¿ANYONE?
[It is possible to represent everything in this universe by using 0 and 1]
I was born intelligent
Education ruined me!.
An idea is useless until it has been implemented.
|
|
|
|
|
What kind of settings?
Kuphryn
|
|
|
|
|
as i said in a dialog..
[It is possible to represent everything in this universe by using 0 and 1]
I was born intelligent
Education ruined me!.
An idea is useless until it has been implemented.
|
|
|
|