473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

struct in C++

In VC++ compiler

struct what
{
int a;
int b;
};

In C, an struct of type "what" is created like: struct what this;
In C++, an object of type "what" can be instantiated like this: what this;
Is this defined in C++ Standard or just VC++ compiler I am using
implemented?


Jul 22 '05 #1
8 1566
C++ Standard defines it. Not VC++ compiler.

"Garma" <Ga*****@nosysserv.com> wrote in message
news:Q_********************@bgtnsc05-news.ops.worldnet.att.net...
In VC++ compiler

struct what
{
int a;
int b;
};

In C, an struct of type "what" is created like: struct what this;
In C++, an object of type "what" can be instantiated like this: what this;
Is this defined in C++ Standard or just VC++ compiler I am using
implemented?

Jul 22 '05 #2
Garma wrote:
In VC++ compiler

struct what
{
int a;
int b;
};

In C, an struct of type "what" is created like: struct what this;
In C++, an object of type "what" can be instantiated like this: what this;
Is this defined in C++ Standard or just VC++ compiler I am using
implemented?


Yes, it is defined in C++ standard. In C++ in this particular context
(declaration) you can do it either way. Keep in mind though that in C++
'this' is a keyword. You can't create an object named 'this'.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #3
Garma wrote:
In VC++ compiler

struct what {
int a;
int b;
};

In C, an [object] of type "struct what" is created like this: struct what this; In C++, an object of type "what" can be instantiated like this:

what this;

Is this defined in C++ Standard?
No.
'this' is a C++ keyword.
Or just VC++ compiler I am using implemented?


The ANSI/ISO C standards define the C programming language.
The ANSI/ISO C++ standards define the C++ programming language

If you define:

typedef struct what {
int a;
int b;
} what;

in C, you can create an object of type "struct what" like this:

what w;

Jul 22 '05 #4

"Garma" <Ga*****@nosysserv.com> wrote in message
news:Q_********************@bgtnsc05-news.ops.worldnet.att.net...
In VC++ compiler

struct what
{
int a;
int b;
};

In C, an struct of type "what" is created like: struct what this;
In C++, an object of type "what" can be instantiated like this: what this;
No it can't - 'this' is a keyword.
Is this defined in C++ Standard or just VC++ compiler I am using
implemented?

Standard - but you can write:
struct what a;
In both C and C++ and it is still needed in some places in C++.
You can also get more C++ like in C by using:
typedef struct
{
int a;
int b;
} what;
what a;

Jul 22 '05 #5

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message > If
you define:

typedef struct what {
int a;
int b;
} what;

in C, you can create an object of type "struct what" like this:

what w;


You've got an extra "what" there, before the {, don't you? Should be just:

typedef struct {
int a;
int b;
} what;
....
what w;

-Howard
Jul 22 '05 #6

"Garma" <Ga*****@nosysserv.com> wrote in message
news:Q_********************@bgtnsc05-news.ops.worldnet.att.net...
In VC++ compiler

struct what
{
int a;
int b;
};

In C, an struct of type "what" is created like: struct what this;
In C++, an object of type "what" can be instantiated like this: what this;
Is this defined in C++ Standard or just VC++ compiler I am using
implemented?


Standard - new "feature" of C++ (over C).
Jul 22 '05 #7
Howard wrote:
E. Robert Tisdale wrote:

If you define:
typedef struct what {
int a;
int b;
} what;

in C, you can create an object of type "struct what" like this:

what w;

You've got an extra "what" there, before the {, don't you? Should be just:

typedef struct {
int a;
int b;
} what;
...
what w;


typedef struct what what;

typedef struct other {
what* p;
// . . .
};

struct what {
int a;
int b;
};

what w;

Jul 22 '05 #8
Howard wrote:
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message > If
you define:
typedef struct what {
int a;
int b;
} what;

in C, you can create an object of type "struct what" like this:

what w;

You've got an extra "what" there, before the {, don't you? Should be just:

typedef struct {
int a;
int b;
} what;
...
what w;

-Howard


The first "what" is the struct's tag. The second is an alternative name
(via typedef) for the type "struct what".

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
10
by: Rick Anderson | last post by:
All, I am receiving the following compilation error on LINUX (but not Solaris, HPUX, WIN32, etc): compiling osr.c LBFO.h(369): warning #64: declaration does not declare anything extern...
5
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used...
19
by: Russell Shaw | last post by:
Hi, I have two structs in a header file, and they reference each other, causing a compile error. Is there a standard way to deal with this? typedef struct { ... RtAction *actions; }...
16
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
5
by: Johs32 | last post by:
I have a struct "my_struct" and a function that as argument takes a pointer to this struct: struct my_struct{ struct my_struct *new; }; void my_func(struct my_struct *new); I have read...
7
by: Alex | last post by:
If I have two struct. See below: struct s1 { int type; int (*destroy)(struct s1* p); } struct s2 { struct s1 base;
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
4
by: hugo.arregui | last post by:
Hi! I have two struts like that: struct { int num; int num2; struct b arrayOfB; } a;
4
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.