Hello everyone I'm trying to create nested structs then use it but I can't do it
what I've done is
public struct number
{
int[] linenumber;
public struct information
{
public linenumber name, surname, id, phone;
}
}
what I'm trying to do is create an array of line number and each number in the stack should hold the name surname id and phone information..
to use this i write number inf = new number();
and then try to inf.linenumber[n].name // where n is my counter.. but it doesn't work, any ideas what i have to do?
thanks in advance
You should write something like this.
public struct number
{
public information[] linenumber;
public struct information
{
public string name, surname, id, phone;
}
}
Related
I'm trying to build documentation using doxygen 1.8.8 based on a large set of structs, and would like for the documentation to reference not only which structs I'm having, but also where the structs are used. Please note that the source code is constructed from an external system, where I do some search and replace to make it into a structure similar to the following:
struct intersect {
int aValue;
};
struct foo_intersect_SET {
order next;
foo owner;
intersect member;
};
struct intersect_bar_SET {
order next;
intersect owner;
bar member;
};
struct another_SET {
order ascending;
something owner;
foo member;
bar member2;
intersect member3;
};
I can get doxygen to build documentation, but when searching for "intersect" it only shows "intersect" and "intersect_bar_SET", I would like it to also display the "foo_intersect_SET" and possibly "another_SET".
And also when viewing the "intersect" struct I would like to get a list where it is used, i.e. that it is used by both "foo_intersect_SET", "intersect_bar_SET" and "another_SET".
Do you know if either of these are possible using doxygen?
One possible way to address this, which I'm currently pursueing is to change the structs into classes, and using multiple inheritance to get the connections both ways. In other words I have to make a temporary version which currently looks something like:
class foo : protected another {
}
class bar : proteced intersect_bar, protected another {
}
class intersect : protected foo_intersect, protected another {
int aValue;
};
class foo_intersect : private foo {
order next;
foo o_foo;
intersect m_intersect;
};
class intersect_bar : private intersect {
order next;
intersect o_intersect;
bar m_bar;
};
class another : private something {
order ascending;
something o_something;
foo m_foo;
bar m_bar;
intersect m_intersect;
};
This is not an ideal solution, but using the inheritance diagram and collaboration diagram I do get most of the information that I want out of it! One caveat is that the original set structure allows for circular definitions, which in turn leads to circular inheritance which of course is not legal...
I'm a C# programmer trying to muddle through C++ to create a Windows Forms Application.
I have a Windows Form that makes use of a user-created class. Basically I'm trying to use a constructor that takes parameters, but my form won't let me initialize the object with parameter. Here's the code, hopefully somebody can explain the problem to me because I'm completely baffled...
Here's my header file: BankAcct.h
public ref class BankAcct
{
private:
int money;
public:
BankAcct();
BankAcct(int);
void Deposit(int);
void GetBalance(int&);
};
And my definition file: BankAcct.cpp
#include "StdAfx.h"
#include "BankAcct.h"
BankAcct::BankAcct()
{
money = 0;
}
BankAcct::BankAcct(int startAmt)
{
money = startAmt;
}
void BankAcct::Deposit(int depAmt)
{
money += depAmt;
}
void BankAcct::GetBalance(int& balance)
{
balance = money;
}
And finally my main form. Won't copy the whole thing, of course, but I'm trying to declare the new bank account object, and start it with a balance of say $50.
private:
BankAcct myAccount(50); //does not work! WHY??
//private:
//BankAcct myAccount; //works
then in the form constructor my code is this:
public:
frmBank(void)
{
InitializeComponent();
int bal;
myAccount.GetBalance(bal);
lblBankBalance->Text += Convert::ToString(bal);
}
I've included the BankAcct.h file at the top of my frmBank.h, what else am I doing wrong here? It works great if I use the default constructor (the one that starts the bank balance at zero). I get the following error messages:
error C2059: syntax error: 'constant'
and
error C2228: left of '.GetBalance' must have class/struct/union
Thank you for any and all help on this one!!
C#-style initialization does not work in C++. You need to put initializers in the initialization section of your constructor (i.e. between : and the opening brace { of the constructor:
public:
MyForm() : myAccount(50) {
// Your constructor
}
private:
BankAcct myAccount;
The way you have it now, myAccount is not defined as BankAcct, so calls of GetBalance do not compile either.
One easy workaround:
private:
BankAcct *myAccount; // Make this a pointer
... then ...
frmBank(void)
{
InitializeComponent();
myAccount = new BankAcct(50);
int bal = myAccount->GetBalance(bal);
lblBankBalance->Text += Convert::ToString(bal);
There are other approaches, too. But I think explicitly creating the "myAccount" object is arguably the clearest and simplest. IMHO...
I'm still new to writing extensions. I'm trying to get this to be the outcome:
class FooClass {
private $elements = array();
}
I'm getting an error when instantiating FooClass:
PHP Fatal error: Cannot access private property ArrayClass::$elements
I know exactly why that's happening I just don't know the correct way of creating a class definition as an array. This is what I have so far, I'm sure it's trivial:
static zend_class_entry *foo_class_ptr;
void create_class_properties(TSRMLS_D) {
zend_declare_property_null(foo_class_ptr, "elements", strlen("elements"), ZEND_ACC_PRIVATE);
}
ZEND_METHOD(foo_class, __construct) {
zval *this = getThis();
zval *elements;
MAKE_STD_ZVAL(elements);
array_init(elements);
add_property_zval_ex(this, "elements", sizeof("elements"), elements);
}
static zend_function_entry foo_class_methods_def[] = {
PHP_ME(foo_class, __construct, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
void create_class_def(TSRMLS_D) {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "FooClass", foo_class_methods_def);
foo_class_ptr = zend_register_internal_class(&ce);
}
create_class_def get's called from PHP_MINIT_FUNCTION(). There's a similiar question here: How do I add an array as an Object Property to a class declared within a PHP extension? but it does not address private/protected access.
thx
The easiest way would probably be to use zend_update_property:
void zend_update_property(zend_class_entry *scope, zval *object, const char *name, int name_length, zval *value TSRMLS_DC);
name_length is excluding the terminator.
struct Limit
{
float Price;
int size;
int Volume;
struct Limit *Parent;
struct Limit *ltChild;
struct Limit *rtChild;
struct list_head* Order;
};
typedef struct Limit Limit;
struct Order
{
double idNum;
bool BuySell;
int shares;
float limitPrice;
char* entryTime;
char* eventTime;
struct list_head ord_Queue;
};
typedef struct Order Order;
void AddOrder(Order* newOrder,Limit* Limit,HXmap* OrderMap)
{
list_add_tail(&newOrder->ord_Queue,Limit->Order);
HXmap_add(OrderMap,&newOrder->idNum,newOrder);
Limit->size++;
Limit->Volume +=newOrder->shares;
}
void ModifyOrder(float oLimit, int oShares,float nLimit,int nShares,HXmap* LimitMap,HXmap* OrderMap, oBook* OrderBook)
{
Limit* ParentLimit = (Limit*)HXmap_get(LimitMap,&oLimit);
if(ParentLimit==NULL)
{
printf("ERRONEOUS ORDER\n");
return;
}
struct list_head *pos;
pos = ParentLimit->Order->next;
Order* Ord= NULL;
while(pos!=ParentLimit->Order)
{
Ord = list_entry((pos),Order,ord_Queue);
if(Ord->shares==oShares)
break; //found the order
else pos = pos->next;
}
if(pos==ParentLimit->Order && Ord->shares!=oShares)
{
printf("ORDER NOT FOUND\n");
return;
}
if(oLimit==nLimit)
{
ParentLimit->Volume = (ParentLimit->Volume + nShares)-oShares;
Ord->shares = nShares;
}
else
{
//delete from list
Ord->ord_Queue.next->prev = Ord->ord_Queue.prev;
Ord->ord_Queue.prev->next = Ord->ord_Queue.next;
ParentLimit->size--;
HXmap_del(OrderMap,&Ord->idNum);
if(ParentLimit->Volume==Ord->shares)
{
if(Ord->BuySell==1)
OrderBook->buyTree = RemoveLimit(OrderBook->buyTree,ParentLimit,LimitMap);
else
OrderBook->sellTree = RemoveLimit(OrderBook->sellTree,ParentLimit,LimitMap);
}
else
ParentLimit->Volume-=Ord->shares;
Ord->limitPrice = nLimit;
Ord->shares = nShares;
INIT_LIST_HEAD(&Ord->ord_Queue);
ParentLimit = HXmap_get(LimitMap,&nLimit);
if(ParentLimit==NULL)
{
ParentLimit = Limit_init(nLimit);
if(Ord->BuySell==1)
OrderBook->buyTree= AddLimit(OrderBook->buyTree,ParentLimit,LimitMap);
else
OrderBook->sellTree = AddLimit(OrderBook->sellTree,ParentLimit,LimitMap);
}
AddOrder(Ord,ParentLimit,OrderMap);
}
}
Okay, its a longish code, but much of it is purely intuitive. [It uses list.h Kernel Linked List and its associate functions.More info about KLL can be found here ]The idea, is when a message to modify a preexisting order at a particular price(its a financial code) arrives, it removes the order from the previous "queue" of its old Price (ParentLimit in ModifyOrder() ) finds the address of new limit price structure by querying the map, if it doesnt exist, creates a new limit and add the order else it simply adds it.
Now, I enter same message of modifying orders in a particular limit price.
Configuration before passing the messages:
Limit Price : 181.25, two orders of 250 shares each.
When I pass, the first modify message, to modify the first order of 250 shares from 181.25 to 181.35(no previous limit exists so it will create a new limit and add it to the tree), the control eventually flows to AddOrder() hence, adding the orders. Definition of AddOrder() function is attached, though its very simplistic and calls list_add_tail() to add it to list.
After the first modification(and addition of order), the DDD gives me this situation:
Address of ParentLimit: 0x804f1d0
Address of ->Order: 804f710
Contents of ->next: 804dec4
Contents of ->prev: 804dec4
Address of Order->ord_Queue (just inserted): 0x804dec4
Contents of Order->ord_Queue->prev: 0x804f710
Contents of Order->ord_Queue->next: 0x804f710
This shows the addition of the order to the queue has taken place successfully.
When I pass the second message to modify another order at the same old price (181.25 to 181.35) and query the map to find me the address of the new Limit Price,
The situation is:
Address of ParentLimit: 0x804f1d0
Address of ->Order: 804f710
Contents of ->next: 804f710
Contents of ->prev: 804f710
Which means, that somehow the change made was not made permanent. I dont know why this is happeneing.
This is the behavior you expect, given your description of where you are querying. These lines will remove the order from your linked list before your query the map to get a ParentLimit for the new price:
Ord->ord_Queue.next->prev = Ord->ord_Queue.prev;
Ord->ord_Queue.prev->next = Ord->ord_Queue.next;
To clarify: Limit.Order is a pointer. It will follow your list head even when you move it to other lists. Thus, deleting from from your old list ends up following a pointer to your new list if you only have one order. You will either need to make it an embedded struct or keep a dummy head that is empty for both new and old lists.
Ive managed to parse the entire contents of a given input text file and store each word in a hash set. But now i need to find the frequenct of each of these words in this input file, any suggestions as to how I can go about? :)
Use a HashMap instead of a HashSet and this class as the value:
class Counter {
public int frequency;
}
addWord() then looks like this:
public void addWord (String word) {
Counter c = map.get (word);
if (c == null) {
c = new Counter ();
map.put(word, c);
}
c.frequency ++;
}