标签: structure

Zend Framework应用程序的默认模块化目录结构

我知道手册中Zend Framework模块化应用程序的默认目录结构.

/application
  /controllers
  /modules
    /admin
      /controllers
      /views
  /views
  /configs
/www
  index.php
Run Code Online (Sandbox Code Playgroud)

但我想知道我为什么要这样做.在/ application/ application/modules /:moduleName中的其他模块中使用默认模块真的很麻烦.这更像是一个讨论问题,而不是一个帮助我的问题.

具有如下目录结构的优点和缺点是什么:

/application
  /modules
    /admin
      /controllers
      /views
    /default
      /controllers
      /views
  /configs
/www
  index.php
Run Code Online (Sandbox Code Playgroud)

从我的观点来看,唯一的缺点是它在默认情况下/在手动中不是这样写的.我看不到任何其他的东西.我错过了什么吗?

更多 - 我认为这个结构应该是任何新ZF应用程序的默认结构.我想知道为什么Zend开发人员不使用它.

directory zend-framework structure

3
推荐指数
1
解决办法
4634
查看次数

为什么前向声明不适用于类?

int main() {
    B bb;                           //does not compile (neither does class B bb;)
    C cc;                           //does not compile

    struct t tt;                    //compiles

    class B {};                     //HERE is the class B defination
    struct s { struct t * pt; };    //compiles
    struct t { struct s * ps; };

    return 0;
}

class C {};
Run Code Online (Sandbox Code Playgroud)

我刚修改了这里给出的例子.

为什么结构转发声明有效,而不是类前向声明​​?

它是否与名称空间有关 - tag namespace而且typedef namespace?我知道没有typedef的结构定义会转到标记命名空间.

结构只是包含所有公共成员的类.所以,我希望他们的行为类似.

c++ structure class forward-declaration

3
推荐指数
1
解决办法
3905
查看次数

初始化结构的向量

我有

struct Vector {

    float i,j,k;
}
Run Code Online (Sandbox Code Playgroud)

我想将以下声明的vec的所有元素归零(i,j,k = 0)

std::vector <Vector> vec;
vec.resize(num,0);
Run Code Online (Sandbox Code Playgroud)

我不想使用reserve()然后push_back()逐个零.另一件事是,在成功初始化vec之后,我想在操作之后将vec的所有成员再次设置为零.有没有类似memset的矢量?

编辑: 我比较了Mike Seymour和Xeo的答案中的所有方法,size_t size = vec.size(); vec.clear(); vec.resize(size);如果它们在循环中频繁重复,则结果 最快.

c++ structure initialization vector

3
推荐指数
1
解决办法
7329
查看次数

数组结构铸造

我有这三种结构,

typedef struct serial_header {
    int zigbeeMsgType;
    int seqNumber;
    int commandIdentifier;
    int dest;
    int src;
}serial_header_t;


typedef struct serial_packet {
  serial_header_t header;
  int data[];
} serial_packet_t;
Run Code Online (Sandbox Code Playgroud)

最后一个是

typedef struct readAttributePacket
{
     int                     u8SourceEndPointId;
     int                     u8DestinationEndPointId;
     int                     u16ClusterId;
     int                     bDirectionIsServerToClient;
     int                     u8NumberOfAttributesInRequest;
     int                     bIsManufacturerSpecific;
     int                     u16ManufacturerCode;
     int                     pu16AttributeRequestList[];
}readAttributePacket_t;
Run Code Online (Sandbox Code Playgroud)

我对此代码感到不安,我只想将驻留在serial_packet_t中的data []数组转换为readAttributePacket_t结构.我认为数据[]应该是

data[]={0x01,0x01,0x04,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01};
Run Code Online (Sandbox Code Playgroud)

我需要将这些数据转换为readAttributePacket_t结构.但是这下面的代码显示错误.

void main()
{
int a[]=  {0x32,0x00,0x31,0x69,0x69,0x00,0x00,0x01,0x01,0x04,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01};
int i;
readAttributePacket_t *p;
serial_packet_t *data;

data = (serial_packet_t*)&a;

for(i=0;i<20;i++){
    printf(" %02x \n",a[i]);
}
p = (readAttributePacket_t *)&data->data;
printf("\nu8SourceEndPointId:%x \nu8DestinationEndPointId:%x \nu16ClusterId:%04x \nbDirectionIsServerToClient:%x …
Run Code Online (Sandbox Code Playgroud)

c arrays pointers structure

3
推荐指数
1
解决办法
6703
查看次数

按值传递和返回结构(带有数组成员)

我知道在C中你可以按值传递(或返回)一个结构但你不能按值传递一个数组.当结构包含数组时会发生什么?结构是按值传递(或返回)时是否会复制数组(在结构中)?我在ideone.com上运行了一个样本并且它可以工作,但是我想知道这个标准在哪里被覆盖(是的,我看过了).

http://open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

typedef struct
{
    float aValue;
    int anArray[5];
} myStruct;

myStruct addValueToArray(myStruct in)
{
    myStruct out = in;

    int i;
    for (i = 0; i < 5; i++)
    {
        out.anArray[i] = in.anArray[i] + in.aValue;
    }

    return out;
}
Run Code Online (Sandbox Code Playgroud)

c arrays structure return pass-by-value

3
推荐指数
1
解决办法
1080
查看次数

C-结构内的结构

如果我有这些结构:

struct rec {
 int key;
 double value;
};

struct node {
 struct rec record;
 struct node *next;
};
Run Code Online (Sandbox Code Playgroud)

我必须将项目的字段值复制 struct rec *r到项目中struct node *n,

我可以这样做吗?

n->record.key = r->key;
n->record.value = r->value;
Run Code Online (Sandbox Code Playgroud)

c structure

3
推荐指数
1
解决办法
529
查看次数

print all python Structure字段值

我试图编写一个可以读取.h文件的小程序,然后从.h文件中的struct生成ctypes.Structure类.然后我正在读取结构中的二进制文件.然后我需要打印出所有Structure字段值(包括数组和子结构).我该怎么做?

python ctypes structure

3
推荐指数
2
解决办法
2435
查看次数

删除结构c ++向量中的重复项

我有以下结构.我想将结构存储在矢量中.其次我想删除(context)上的重复值.我究竟做错了什么?


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//Structure
struct contextElement
{
  string context;
  float x;
};

int main()
{
  vector<contextElement> v1;
  v1.push_back({"1",1.0});
  v1.push_back({"2",2.0});
  v1.push_back({"1",1.0});
  v1.push_back({"1",1.0});
  //ERROR here
  auto comp = [] ( const contextElement& lhs, const contextElement& rhs ) {return lhs.context == rhs.context;};
  //Remove elements that have the same context
  v1.erase(std::unique(v1.begin(), v1.end(),comp));
  for(size_t i = 0; i < v1.size();i++)
  {
    cout << v1[i].context <<"  ";
  }
  cout << endl;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:

main.cpp | …

c++ structure vector unique duplicate-removal

3
推荐指数
1
解决办法
2988
查看次数

在结构上操作并将结果分配给相同的结构是不好的做法吗?为什么?

我不记得看到像这个假设片段的代码示例:

cpu->dev.bus->uevent = (cpu->dev.bus->uevent) >> 16; //or the equivalent using a macro  
Run Code Online (Sandbox Code Playgroud)

其中大型结构中的成员使用指针取消引用,操作,并将结果分配回结构的同一字段.

内核似乎是一个频繁出现如此大型结构的地方,但我还没有看到它的例子,并对其原因产生了兴趣.

是否存在性能原因,可能与遵循指针所需的时间有关?这不是好风格,如果是这样,首选方式是什么?

c c++ performance kernel structure

3
推荐指数
1
解决办法
167
查看次数

从函数返回指向结构的指针

我一直在尝试使用以下代码返回一个指向函数结构的指针,该函数接受一个结构并返回一个指向它的指针:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct mystruct
{
    int id;
    char name[10];
};


//this is the function
struct mystruct *return_pointer(struct mystruct a)
{
    struct mystruct *ptr;
    ptr = &a;
    return ptr;
}

int main()
{
    struct mystruct tag, *p;
    tag.id = 12;
    strcpy(tag.name,"abcd");

    printf("Values are: %d\t%s",tag.id,tag.name);
    p=return_pointer(tag);

    printf("\nValues through pointer: %d\t%s", p->id, p->name);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用返回的指针访问结构的值时,它无法正常工作.它只显示'id'而不是'name'.这可能是什么问题?我已经在一本书中读过,该书曾说过在函数体中使用它:

ptr = (struct mystruct *)malloc(sizeof(struct mystruct));
ptr-> id = a.id; 
strcpy(p->name,a.name); 
//struct 'a' is argument to function

return ptr;
Run Code Online (Sandbox Code Playgroud)

如果这是正确的解决方案那么为什么呢?

c pointers structure

3
推荐指数
1
解决办法
84
查看次数