473,387 Members | 1,530 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,387 software developers and data experts.

how to change the value of an object ?

May I change the value of data members of an object by using the
constructor?

struct A
{
int x;
default y;
}

int main()
{
A aobj;
}

aobj is an object of the class A, and I want to change the values of x
and y of the aobj, how can I do? Thanks.

Dec 3 '06 #1
7 2037
asdf wrote:
May I change the value of data members of an object by using the
constructor?

struct A
{
int x;
default y;
}

int main()
{
A aobj;
aobj.x = 1;
aobj.y = aobj.y;
}

aobj is an object of the class A, and I want to change the values of x
and y of the aobj, how can I do? Thanks.
Dec 3 '06 #2
asdf wrote:
May I change the value of data members of an object by using the
constructor?

struct A
{
int x;
default y;
}

int main()
{
A aobj;
}

aobj is an object of the class A, and I want to change the values of x
and y of the aobj, how can I do?
In your case, e.g.:

aobj.x = 5;
aobj.y = 7 - aobj.y + aobj.x;
Best

Kai-Uwe Bux
Dec 3 '06 #3
Kai-Uwe Bux wrote:
asdf wrote:

struct A
{
int x;
default y;
}

In your case, e.g.:

aobj.x = 5;
aobj.y = 7 - aobj.y + aobj.x;
I'm not familiar with this "default y;" syntax, and my compiler
doesn't accept it .. can you fill me in?

Dec 3 '06 #4
"asdf" <li*********@gmail.comwrote in message
news:11********************@79g2000cws.googlegroup s.com...
May I change the value of data members of an object by using the
constructor?
No. A constructor is only invoked at creation time.
It is used to initialize an object.

struct A
{
int x;
default y;
'default' is a reserved word in C++. You can't use
it as a type or a name.
}

int main()
{
A aobj;
}

aobj is an object of the class A, and I want to change the values of x
and y of the aobj, how can I do? Thanks.

struct A
{
int x;
int y;
A(int x_parm, int y_parm) : x(x_parm), y(y_parm) /* constructor */
{
}

int main()
{
A obj(1, 2); /* creates a type 'A' object whose member 'x'
is initialized to 1, and whose member 'y'
is initialized to 2 */

obj.x = 42; /* changes member 'x' */
obj.y = 99; /* changes member 'y' */

return 0;
}

-Mike
Dec 3 '06 #5
Old Wolf wrote:
Kai-Uwe Bux wrote:
>asdf wrote:
>
struct A
{
int x;
default y;
}

In your case, e.g.:

aobj.x = 5;
aobj.y = 7 - aobj.y + aobj.x;

I'm not familiar with this "default y;" syntax, and my compiler
doesn't accept it .. can you fill me in?
Nope. Maybe the OP can.
Best

Kai-Uwe Bux
Dec 3 '06 #6
On 3 Dec 2006 12:55:36 -0800 in comp.lang.c++, "Old Wolf"
<ol*****@inspire.net.nzwrote,
>I'm not familiar with this "default y;" syntax, and my compiler
doesn't accept it .. can you fill me in?
The 'default' keyword is not legal in that context at all. One can only
assume that the code posting got mangled by a Microsoft spellchecker.

Dec 3 '06 #7
"asdf" <li*********@gmail.comwrote in message
news:11********************@79g2000cws.googlegroup s.com...
May I change the value of data members of an object by using the
constructor?

struct A
{
int x;
default y;
I presume this is supposed to be
int y;
}

int main()
{
A aobj;
}

aobj is an object of the class A, and I want to change the values of x
and y of the aobj, how can I do? Thanks.
It's called the dot operator.

aobj.x
If aobj is a pointer then you use the arrow operator:
A* aobj = new A;
aobj->x
although you can also dereference the pointer and use the dot operator
(*aobj).x
Dec 3 '06 #8

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

Similar topics

2
by: Stephan Walter | last post by:
Hi, I'm hacking on a LISP interpreter in JS , and running into trouble with numbers and Number objects. This is what I have: var a = new Number(1); var b = a; document.writeln(a == b); ...
0
by: ghanley | last post by:
I have searched the web all day for a lead on this. I have found how to control the Graph object mut not the embedded excel unbound object frame. I am trying to chart the data below on one...
2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
3
by: spielmann | last post by:
Hello I want to change the scrollbar size of windows, How can I do that with vb.net I have find this in VB6 but how can we convert simply this code. thx
15
by: Encapsulin | last post by:
Hello everybody. I'm trying to change src of quicktime embedded object with javascript: <html><body> <script language="JavaScript"> function Exchange() { document.qtvr.src = "sample2.pano";...
10
by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column...
2
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
17
by: Summercool | last post by:
I wonder which language allows you to change an argument's value? like: foo(&a) { a = 3 } n = 1 print n
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.