m****s 发帖数: 79 | 1 我也被问过这个问题。
我说我不知道。
我只是简单的只有数据的时候我就用struct,复杂的有member
functions的时候用class.
面试回来上网查到了答案。 |
|
f******l 发帖数: 26 | 2 can you say:
strcut A {
...
}
struct B : A {
...
} |
|
k****i 发帖数: 1072 | 3 struct MyStruct
{
int x, y;
public MyStruct(int x, int y)
{
this.x = x;
this.y = y;
}
public void Change()
{
this=new MyStruct(1,1);
Print();
}
public void Print()
{
System.Console.WriteLine(this.x);
}
}
Remember, "this" is a value in class
a
this" |
|
s*******k 发帖数: 20 | 4 My understanding is:
"this" in class is a value, not a variable; while in struct, it is a variable,
which represents a storage location, mostly likely the containing variable
itself.
Am I right?
Further question regarding "this is a value in class": What is the value of
this in class then? |
|
g*****g 发帖数: 34805 | 5 If you are going to write out and read in again, it's even simpler.
Just write the number of numbers or sizeof(struct) into the file first. |
|
b*********n 发帖数: 1258 | 6 如果我把sizeof(struct)先写进去的话
reader program 怎么知道里面有多少个数字?
还是需要write out 那个occurrence number.
有什么方法可以避免那个occurrence number吗? |
|
z**********r 发帖数: 86 | 7 我是这么用的(verified on Ubuntu):
typedef struct
{
// fixed length data
int len;
// any varying length data should be put below
// note, you must be used data[] instead of *data
// because data[] does't take extra space; *data takes four bytes for the
pointer
char data[];
}Array;
// for allocate
int len=10;
Array *x=(Array *)malloc(len*sizeof(char)+sizeof(Array));
x->len=10;
// access the varying length part
x->data[0]='c';
// for deallocate
free(x); |
|
t****t 发帖数: 6806 | 8 class/struct Child : {default} Parent {
//if (keyword == class) default=private;
//else default=public;
}; |
|
f******n 发帖数: 90 | 9 sometimes I see people use struct FILE, and sometimes people use FILE
directly. What's the difference? |
|
t****t 发帖数: 6806 | 10 there should not be any "struct FILE" unless you define one (in which case,
they are equivalent). |
|
f******n 发帖数: 90 | 11 or is there anything like: "struct file" ?
em, I don't why, but I kind of saw such thing somewhere before. |
|
t****t 发帖数: 6806 | 12 of course you can define a "struct file" |
|
s*******d 发帖数: 59 | 13 C++里面不需要,可能为了兼容C,很多都会有个
typedef struct tag_A A; |
|
p***o 发帖数: 1252 | 14 how about this?
struct xxx {double x, y, z;};
union
{
double xa[3];
xxx v;
};
however, you need to use vec.v.x, vec.v.y, vec.v.z
if you insist on vec.x, vec.y, vex.z, probably #define
could be used, just as sockaddr_in |
|
j*****j 发帖数: 115 | 15 typedef struct
{
int val;
list* next;
} list;
为什么这段代码我不能编译通过? |
|
d****p 发帖数: 685 | 16 Are you using C++ compiler or C compiler?
JavaVM is a struct when it is in C++ mode. |
|
d****p 发帖数: 685 | 17 Yes so you are under c mode where JavaVM is a pointer to struct. |
|
m******t 发帖数: 4077 | 18 下面这种情况
struct X {
int i;
int j;
}
X x1 = {1, 2};
是直接把value assign给i,j了吗? 这个过程中default constructor做了什么事情吗? |
|
|
m******t 发帖数: 4077 | 20 难道c++里面的struct不就是class吗?default public就是了。 |
|
c*********e 发帖数: 16335 | 21 struct没有constructor/destructor.没有inheritance. |
|
t****t 发帖数: 6806 | 22 in this case, struct X is called an "aggregate", i.e. you have no user-
defined ctor, no private, no base, no virtual; then you can use initializer
list.
by definition, default ctor is used when no initializer is used, so in your
case it does not apply.
吗? |
|
o****e 发帖数: 916 | 23 struct data {
unsigned int a : 3;
}
这个里面":3"是干嘛用的啊?谢谢! |
|
c*********e 发帖数: 16335 | 24 struct data {
unsigned a : 3;
}
a占3 bit. |
|
w*s 发帖数: 7227 | 25 in c code i can do this
func(struct aaa *)
{
aaa->f1 = 1;
aaa->f2 = "abc";
}
how to do this in python pls ? |
|
|
N******K 发帖数: 10202 | 27 struct pixel
{
double a // 8 byte
double b // 8 byte
}
auto pointer = new pixel[10]
pointer += 9
这个计算 是怎么实现的
是不是 逻辑上相当于 **pointer += 9*16
**pointer是指针的值 uint64类型 内存单元为byte |
|
G*O 发帖数: 687 | 28 【 以下文字转载自 Engineering 讨论区 】
发信人: GEO (CEO), 信区: Engineering
标 题: [合集] 昨天的PE(Civil/Struct Depth)考试小结
发信站: BBS 未名空间站 (Fri Jul 27 20:45:36 2007), 站内
☆─────────────────────────────────────☆
ZQBX (以默默潜水为荣,以掐架恶灌为耻!) 于 (Sat Apr 22 08:20:24 2006) 提到:
AM:
都是基本概念。除了Lindeburg的CERM,几乎不需要其他任何书。这次只有一个概念题
CERM里面没有查到,在Das的Fundamentals of Foundation Engineering里查到了(即使没
有,应该还是凭判断能答对。)
建议:
1. 打印CERM后面的INDEX并单独装订,这样在查找时比较省时省劲。
2. 把NCEES的FE SSupplied-reference Handbook中的Civil Engineering的章节搞懂。
PM:
我选的是Structur |
|
f****m 发帖数: 32 | 29 One question please:
Can MPI_bCast a struct? If not, how to broadcast a bunch of arrays in
different data type?
Thanks |
|
z*********n 发帖数: 1451 | 30
也放松一下,贴个以前写的编译时间计算int to Roman number的C++ metaprogramming
, 学生时在实验室天天就玩这种东西了:
class R2I {
const static int DIG;
public:
constexpr static char IN[] = "MCDXLVI"; ///This is the INPUT number;
const static int OUT;
};
template struct ID {};
template <> struct ID <'I'> { static const int I = 0; static const int V = 1
; };
template <> struct ID <'V'> { static const int I = 1; static const int V = 5
; };
template <> struct ID <'X'> { static const int I = 2; static const int V =
10... 阅读全帖 |
|
s******g 发帖数: 755 | 31 【 以下文字转载自 Apple 讨论区 】
发信人: faucetQ (fq), 信区: Apple
标 题: [Mac Dev]整了个ObjectiveC的笔记,看看气氛对得上不
发信站: BBS 未名空间站 (Mon Feb 2 21:38:18 2009), 转信
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk... 阅读全帖 |
|
f*****Q 发帖数: 1912 | 32 整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk的语法基本是相同的。
当有两个或者两个以上的参数时,通常试用以的语法
[ obj method:parameter1 WithSecondParameter:parameter2];
定义一个类的代码放在一个.h文件中,下面是一个例子。
//macdevexample1.h
... 阅读全帖 |
|
H**********5 发帖数: 2012 | 33 #include
#include
typedef struct node
{
int data;
struct node* next;
};
void printfList(struct node *head)
{
while(head!=NULL)
{
printf("%d-> ",head->data);
head=head->next;
}
printf("\n");
}
void pushAtBegin(struct node **head_ref,int data)
{
struct node *new_node=(struct node*)malloc(sizeof(struct node));
new_node->data=data;
new_node->next=*head_ref;
*head_ref=new_node;
}
void pushAtEnd(struct node **head_ref,i... 阅读全帖 |
|
i**p 发帖数: 902 | 34 最近编译运行了《Essential Linux Device Drivers》第5章的例子,
Driver for the Parallel LED Board (led.c)。程序不复杂。其中有一个函数led_
attach(struct parport *port) 是由parport_register_driver(&led_driver)注册的。
请问,led_attach()是何时被调用的?或者说怎么引起系统调用这个函数?
----------------------------------------
I double checked my code again. Though I use the same name as the link http://www.spinics.net/lists/newbies/msg38087.html suggested, the
led_attach() is not called.
code is here.
#include
#include
#include 阅读全帖 |
|
i**p 发帖数: 902 | 35 I double checked my code again. Though I use the same name as the link http://www.spinics.net/lists/newbies/msg38087.html suggested, the
led_attach() is not called.
code is here.
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME "led"
static dev_t dev_number; /* Allotted device number */
static struct class *led_class; /* Class to which ... 阅读全帖 |
|
m*********n 发帖数: 28 | 36 后面的补充想法是对的。给你个范例程序
struct SexOrgan {
};
struct Asshole : public SexOrgan {
};
struct Dick : public SexOrgan {
};
struct Pussy : public SexOrgan {
void Eat(Dick& dick) {
};
};
void B2B(Pussy& p0, Pussy& p1) {
}
struct HumanBeing {
virtual void BangWith(HumanBeing & that) {
// take off all clothes;
}
};
struct Female;
struct Male : public HumanBeing {
virtual void BangWith(HumanBeing& that) {
HumanBeing::BangWith(that);
Female* female = dynamic_cast阅读全帖 |
|
i**p 发帖数: 902 | 37 【 以下文字转载自 Programming 讨论区 】
发信人: isup (No), 信区: Programming
标 题: 哪位用过tty_flip_buffer_push()?
发信站: BBS 未名空间站 (Sun Jun 15 17:43:46 2014, 美东)
I am trying to run tiny_tty in LDD3. When I use "cat /dev/ttty0" to read
from it, there is no output and the command is blocked.
Checking the trace, I notice both tty_insert_flip_char() and tty_flip_buffer
_push() are called. However, the data is not sent to the user by tty core.
Instead, it is sent back to the tiny_tty driver's tiny_write() callback
functio... 阅读全帖 |
|
i**p 发帖数: 902 | 38 I am trying to run tiny_tty in LDD3. When I use "cat /dev/ttty0" to read
from it, there is no output and the command is blocked.
Checking the trace, I notice both tty_insert_flip_char() and tty_flip_buffer
_push() are called. However, the data is not sent to the user by tty core.
Instead, it is sent back to the tiny_tty driver's tiny_write() callback
function. What is wrong there?
The kernel version is 2.6.32-61-generic.
static void tiny_timer(unsigned long timer_data)
{
struct tiny_serial *... 阅读全帖 |
|
f*****y 发帖数: 444 | 39 I am preparing algorithm, wrote the following algorithm. Share with you. Not
sure whether it is a duplicate post or not.
//---- Breadth Fast Search algorithm ---
// circular queue
int head = 0;
int tail = 0;
#define Q_EMPTY (head==tail)
#define Q_FULL ((tail-head+1)%SIZE==0)
#define SIZE 10
struct Node* q[SIZE];
void put(struct Node* x)
{
if (x==NULL) return;
if (Q_FULL) return; //queue full
q[tail] = x;
tail = (tail+1) % SIZE;
return;
}
struct Node* get()
{
if (Q_EMPT... 阅读全帖 |
|
x*****0 发帖数: 452 | 40 Given a linked list where in addition to the next pointer, each node has a
child pointer, which may or may not point to a separate list. These child
lists may have one or more children of their own, and so on, to produce a
multilevel data structure, as shown in below figure.You are given the head
of the first level of the list. Flatten the list so that all the nodes
appear in a single-level linked list. You need to flatten the list in way
that all nodes at first level should come first, then nod... 阅读全帖 |
|
m********o 发帖数: 796 | 41 【 以下文字转载自 Linux 讨论区 】
发信人: momoxinduo (馍馍), 信区: Linux
标 题: 弱弱的问个内核遍历当前进程的子进程的一小段程序
发信站: BBS 未名空间站 (Wed Aug 21 01:23:39 2013, 美东)
linux内核里遍历当前进程的子进程的一小段程序有点看不太明白
struct task_struct *task;
struct list_head *list;
/* 这里的 struct list_head 的定义是两个指向他自己的指针
* struct list_head
* {
* struct list_head *next, *prev;
* }; */
/* 下面的list_for_each宏定义
*list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list. */
... 阅读全帖 |
|
m********o 发帖数: 796 | 42 linux内核里遍历当前进程的子进程的一小段程序有点看不太明白
struct task_struct *task;
struct list_head *list;
/* 这里的 struct list_head 的定义是两个指向他自己的指针
* struct list_head
* {
* struct list_head *next, *prev;
* }; */
/* 下面的list_for_each宏定义
*list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list. */
#define list_for_each(pos, head)
for (pos = (head)->next; prefetch(pos->next), pos != (head); pos =
pos->next) ... 阅读全帖 |
|
m******t 发帖数: 4077 | 43 非常简单一个程序
struct B {
struct B *next;
}
struct A {
int C;
struct B;
}
int
main()
{
struct B ** np;
tmp = (struct A *) malloc (sizeof(struct A));
np = &(tmp->B->next);
free(tmp);
printf("*np is %p", *np);
return 0;
}
按说free了tmp以后B->next就不再存在了,对吧?为什么这个时候还能够正确的
dereference *np呢?
如果把struct A中的B和C换个位置,*np就正确的变成的NULL pointer了。
是不是free memory的时候不wipe memory啊? |
|
c*****t 发帖数: 1879 | 44 最近无聊,稍微研究了下两个语言,彻底被雷了。
第一是 R 。可以说是世界上最 fucked up 的语言之一(COBOL 是另外一个)。
你看一下这篇文章就明白了:
https://xianblog.wordpress.com/2010/09/13/simply-start-over-and-build-
something-better/
如果你非要写 R 代码。建议你把所有的 variable 都弄个 prefix 。免得你
不小心碰到这种麻烦事。
第二就是 Go 。整个一傻逼语言。
1) 如果该语言有 pointer,但是其速度比 Java 还慢点,谁 TMD 有病才用它。
再不用说,Go 里面需要知道很多很多 low level 的东西,但是搞了半天比 Java
还慢?!!
2) Stupid copies 。好吧,你有 pointer 不用,非得 pass by value (i.e.
struct copy),真是脑袋抽筋了。copy 大部分情况下比 reference 慢。
reference 是可以放在 register 里的,而 struct 一旦比 register... 阅读全帖 |
|
c*****t 发帖数: 1879 | 45 最近无聊,稍微研究了下两个语言,彻底被惊呆了。
第一是 R 。可以说是世界上最 fucked up 的语言之一(COBOL 是另外一个)。
你看一下这篇文章就明白了:
https://xianblog.wordpress.com/2010/09/13/simply-start-over-and-build-
something-
better/
第二就是 Go 。整个一傻逼语言。
1) 如果该语言有 pointer,但是其速度比 Java 还慢点,谁 TMD 有毛病才用它。
再不用说,Go 里面需要知道很多很多 low level 的东西,但是搞了半天比 Java
还慢?!!
2) Stupid copies 。好吧,你有 pointer 不用,非得 pass by value (i.e.
struct copy),真是脑袋抽筋了。copy 大部分情况下比 reference 慢。
reference 是可以放在 register 里的,而 struct 一旦比 register 大,
就会占内存。然后 Go idiots 说 cache 很 precious,那你还搞那么多 copy... 阅读全帖 |
|
r*c 发帖数: 167 | 46 二爷,坑爹算法来也。用状态机搞砸一切面面!哈哈
#include
#include
#include
using namespace std;
class Numericality;
void TestNumericality();
void TestNumericalityHelper(const string& str, const bool expected,
Numericality& nc);
class Numericality
{
public:
struct State
{
const string _str;
int _index;
State() {}
State(string s, int i) : _str(s), _index(i){}
virtual State* MoveNext(){
if(_str.empty() || _index < 0 || _index >= _str... 阅读全帖 |
|
R*****i 发帖数: 2126 | 47 这个题目建议用红黑树做可能最快捷有效。红黑树每一次插入,删除都是log(k),求平
均值非常简单,就是根部的那个节点。所以总的计算量是O(nlog(k))。
以下是c/c++代码(需要修改数组,以便一个一个输入)。
#include
#include
#include
#define INDENT_STEP 4
enum rbtree_node_color {RED, BLACK};
typedef struct rbtree_node_t {
int value;
struct rbtree_node_t* left;
struct rbtree_node_t* right;
struct rbtree_node_t* parent;
enum rbtree_node_color color;
} *rbtree_node;
typedef rbtree_node node;
typedef enum rbtree_node_color color;
typedef struct... 阅读全帖 |
|
l*****a 发帖数: 14598 | 48 每个节点保存所有相关人名list.
struct node
{
int number;
struct node* sub[10];
struct list * head;
struct list * tail;
}
struct list
{
char * name;
struct list * next;
}
剩下的就不用了吧? |
|
i*****o 发帖数: 105 | 49 #include
#include
int x[10][10] = {
{ 1, 1, 1, 1, 1, 1, 5, 1, 1, 1,},
{ 1, 1, 1, 1, 1, 1, 4, 1, 1, 1,},
{ 1, 1, 1, 1, 1, 1, 8, 1, 1, 1,},
{ 1, 1, 1, 1, 5, 4, 10, 1, 1, 1,},
{ 1, 1, 1, 1, 4, 1, 10, 10, 1, 1,},
{ 1, 1, 1, 1, 5, 5, 10, 10, 10, 10,},
{ 1, 1, 5, 6, 1, 5, 11, 1, 1, 1,},
{ 1, 1, 3, 1, 1, 1, 10, 1, 1, 1,},
{ 1, 2, 2, 1, 1, 1, 1, 1, 1, 1,},
{ 2, 1, 10, 10,... 阅读全帖 |
|
w*******u 发帖数: 267 | 50 Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-
inorder-traversal/
————————————————————————————————————
我的解法
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* buildTree(int* preorder, int preorderSize, int* inorder,
int inorderSi... 阅读全帖 |
|