Thread: Re: [Dev-C++] Question about class objects
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-10-23 12:09:06
|
>From: Teodorescu Cristian <te...@xt...>
>To: dev...@li...
>Subject: Re: [Dev-C++] Question about class objects
>Date: Wed, 23 Oct 2002 15:00:56 +0200
>
>Daniel Glenfield wrote:
>
>>
>>
>>When I create a class object, can I call a member function right away?
>>
>>I'm thinking that if I have private data I want to initialise when the
>>object is created I could put in a member function that does it, but can I
>>call it immediately? Instead of
>>
>>MyClass ObjectOne;
>>ObjectOne.StartUp();
>>
>>
>>I know that a constructor initialisation list will do the same, can
>>someone show me an example of that as well as I am a little confused by
>>the syntax.
>
>class MyClass{
>public :
> MyClass (int x=0){
> m_intX=x;
> }
>private:
> m_intX;
>}
>
>void main (void ){
> MyClass a,b(10);
> //a.m_intX=0 and in b.m_intX=0;
>}
>for more info read Bruce Eckel thinking in c++ (http://www.mindview.com)
>it's free.
>
>>
>>Daniel
>>
>>
>>
Are you sure
>class MyClass{
>public :
> MyClass (int x=0){
> m_intX=x;
> }
>private:
> m_intX;
>}
>
>void main (void ){
> MyClass a,b(10);
> //a.m_intX=0 and in b.m_intX=0;
>}
is valid? MyClass (int x=0) is that valid? And when you pass 10 to the
constructor, is it not expecting a variable of type int, not an integer?
_________________________________________________________________
Unlimited Internet access -- and 2 months free! Try MSN.
http://resourcecenter.msn.com/access/plans/2monthsfree.asp
|
|
From: Daniel G. <sp...@ho...> - 2002-10-23 12:56:23
|
Oh the site is now mindview.net, not .com from what I gether. Thanks, Daniel _________________________________________________________________ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp |
|
From: Daniel G. <sp...@ho...> - 2002-10-23 14:21:16
|
Ah yes, because a static data member is essentially a global correct? _________________________________________________________________ Internet access plans that fit your lifestyle -- join MSN. http://resourcecenter.msn.com/access/plans/default.asp |
|
From: Teodorescu C. <te...@xt...> - 2002-10-23 12:37:22
|
Daniel Glenfield wrote:
>
>> From: Teodorescu Cristian <te...@xt...>
>> To: dev...@li...
>> Subject: Re: [Dev-C++] Question about class objects
>> Date: Wed, 23 Oct 2002 15:00:56 +0200
>>
>> Daniel Glenfield wrote:
>>
>>>
>>>
>>> When I create a class object, can I call a member function right away?
>>>
>>> I'm thinking that if I have private data I want to initialise when
>>> the object is created I could put in a member function that does it,
>>> but can I call it immediately? Instead of
>>>
>>> MyClass ObjectOne;
>>> ObjectOne.StartUp();
>>>
>>>
>>> I know that a constructor initialisation list will do the same, can
>>> someone show me an example of that as well as I am a little confused
>>> by the syntax.
>>
>>
>> class MyClass{
>> public :
>> MyClass (int x=0){
>> m_intX=x;
>> }
>> private:
>> m_intX;
>> }
>>
>> void main (void ){
>> MyClass a,b(10);
>> //a.m_intX=0 and in b.m_intX=0;
>> }
>> for more info read Bruce Eckel thinking in c++ (http://www.mindview.com)
>> it's free.
>>
>>>
>>> Daniel
>>>
>>>
>>>
>
>
> Are you sure
>
>> class MyClass{
>> public :
>> MyClass (int x=0){
>> m_intX=x;
>> }
>> private:
>> m_intX;
>> }
>>
>> void main (void ){
>> MyClass a,b(10);
>> //a.m_intX=0 and in b.m_intX=0;
>> }
>
>
> is valid? MyClass (int x=0) is that valid
Have you ever heard about default parameters ?
> ? And when you pass 10 to the constructor, is it not expecting a
> variable of type int, not an integer?
it's OK code work except on bug * *int m_intX**
>
>
> _________________________________________________________________
> Unlimited Internet access -- and 2 months free! Try MSN.
> http://resourcecenter.msn.com/access/plans/2monthsfree.asp
>
>
>
> -------------------------------------------------------
> This sf.net emial is sponsored by: Influence the future of Java(TM)
> technology. Join the Java Community Process(SM) (JCP(SM)) program now.
> http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0002en
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--
Best Reagards Teodorescu Cristian Liviu (te...@xt...)
|
|
From: senem b. <sbe...@ya...> - 2002-10-27 12:01:42
|
got a question:
i'd like to copy a char string to a string of pointers but i can't get the code working...and i can't see the result with cout... anyone who can help me??
kind regards,
senem
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define max 5
int main(){
char *array[max];
char string[max];
cout<<"enter string :";
cin.getline(string,max);
strncpy(array[0],string,sizeof(string)/sizeof(char));
cout<<array[0];
return 0;
}
---------------------------------
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site |
|
From: Abhijit S. <mu...@gm...> - 2002-10-27 13:33:43
|
> got a question:
> i'd like to copy a char string to a string of pointers but i can't get the
> code working...and i can't see the result with cout... anyone who can help
> me??
> kind regards,
> senem
> #include <iostream.h>
> #include <stdlib.h>
> #include <string.h>
> #include <stdio.h>
> #define max 5
> int main(){
> char *array[max];
Here, you've just declared an array of pointers. You haven't actually
allocated memory, so the pointers are not valid. You need to new[] it, like
so.
array[0] = new char[max];
and so on.
> char string[max];
> cout<<"enter string :";
> cin.getline(string,max);
> strncpy(array[0],string,sizeof(string)/sizeof(char));
> cout<<array[0];
> return 0;
> }
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|
|
From: Per W. <pw...@ia...> - 2002-10-27 14:40:14
|
But most proably that wasn't the intention.
The fact that both array and string was sized with max must mean
something... in this case a failed attempt at space for the characters. By
mistake, the declaration instead created a number of pointers.
char *ptr;
char string[max];
ptr = new char[max];
strncpy(ptr,string,max);
ptr[max-1] = '\0';
or instead
string[max-1] = '\0';
ptr = strdup(string);
/Per W
On Sun, 27 Oct 2002, Abhijit Shylanath wrote:
> > got a question:
> > i'd like to copy a char string to a string of pointers but i can't get the
> > code working...and i can't see the result with cout... anyone who can help
> > me??
> > kind regards,
> > senem
>
> > #include <iostream.h>
> > #include <stdlib.h>
> > #include <string.h>
> > #include <stdio.h>
> > #define max 5
> > int main(){
> > char *array[max];
>
> Here, you've just declared an array of pointers. You haven't actually
> allocated memory, so the pointers are not valid. You need to new[] it, like
> so.
>
> array[0] = new char[max];
>
> and so on.
>
> > char string[max];
> > cout<<"enter string :";
> > cin.getline(string,max);
> > strncpy(array[0],string,sizeof(string)/sizeof(char));
> > cout<<array[0];
> > return 0;
> > }
>
> ___________________________________________________________
>
> Abhijit Shylanath
>
> E-mail: mu...@gm... || ibr...@bi...
> Web-site: http://mudeth.tripod.com/
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ApacheCon, November 18-21 in
> Las Vegas (supported by COMDEX), the only Apache event to be
> fully supported by the ASF. http://www.apachecon.com
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: senem b. <sbe...@ya...> - 2002-10-28 10:12:42
|
when i try to get the elements back from a function i wrote, i get an error called "access violation" and i don't know what that is.i'd be glad if anyone who has time would look at it...i'm sending one part of the code, the one which doesn't work...
kind regards...
int removecar(int garagenum,char *mystring){
int i=0;
char plaka[10];
if(garagenum==1){
while(strcmp(garage1.plate[i],mystring)==0){
pop(plaka,garage1);
push(plaka,temporary);
i++;
}
while(isempty(temporary)!=1){
pop(plaka,temporary);
push(plaka,garage1);
}
temp_pop(plaka,garage3);
push(plaka,garage1);
return 1;
}
if(garagenum==2){
i=0;
while(strcmp(garage2.plate[i],mystring)==1){
pop(plaka,garage2);
push(plaka,temporary);
i++;
}
while(!isempty(temporary)){
pop(plaka,temporary);
push(plaka,garage2);
}
temp_pop(plaka,garage3);
push(plaka,garage2);
return 1;
}
if(garagenum==3){
if(findel(garage1,mystring)){
while(strcmp(garage1.plate[i],mystring)==1){
pop(plaka,garage1);
push(plaka,temporary);
i++;
}
while(!isempty(temporary)){
pop(plaka,temporary);
push(plaka,garage1);
}
return 1;
}
if(findel(garage2,mystring)){
while(strcmp(garage2.plate[i],mystring)==1){
pop(plaka,garage2);
push(plaka,temporary);
i++;
}
while(!isempty(temporary)){
pop(plaka,temporary);
push(plaka,garage2);
}
return 1;
}
if(temp_findel(garage3,mystring)){
temp_pop(plaka,garage3);
return 1;
}
if(!temp_findel(garage3,mystring)&&!findel(garage2,mystring)&&
!findel(garage1,mystring))
return 0;
}
}
void pop(char *mystring,garage &line){
if(isempty(line)){
cout<<"error,can't pop,stack empty"<<endl;
exit(1);
}
else{
line.top--;
mystring=new char[sizeof(line.plate[line.top])/sizeof(char)];
strcpy(mystring,line.plate[line.top]);
line.elements--;
}
}
void temp_pop(char *mystring,temp_storage &line){
if(temp_isempty(line)){
cout<<"error,can't pop,stack empty"<<endl;
exit(1);
}
else{
line.temptop--;
mystring=new char[sizeof(line.tempplate[line.temptop])
/sizeof(char)];
strcpy(mystring,line.tempplate[line.temptop]);
line.tempelements--;
}
}
---------------------------------
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site |
|
From: Eric R. <e.r...@pa...> - 2002-10-28 19:07:06
|
Hi group Is it possible not to send HTML Emails because they are about 2.5 times bigger than a standard text Email, the one below could of been sent in plain text format and no one would of been the wiser. HTML Email can also carry a type of Email virus. http://www.georgedillon.com/web/html_email_is_evil.shtml (7 REASONS WHY HTML E-MAILS ARE EVIL.) From Eric NO ATTACHMENT WAS SENT WITH THIS EMAIL, IF THERE IS ONE, IT IS A UNDETECTED VIRUS, PLEASE LET ME KNOW.. Black text on white background HTML Emails and replied with white text on white. -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of senem beken Sent: 28 October 2002 23:13 To: dev...@li... Subject: [Dev-C++] elements from an array of pointers... when i try to get the elements back from a function i wrote, i get an error called "access violation" and i don't know what that is.i'd be glad if anyone who has time would look at it...i'm sending one part of the code, the one which doesn't work... kind regards... int removecar(int garagenum,char *mystring){ int i=0; char plaka[10]; if(garagenum==1){ while(strcmp(garage1.plate[i],mystring)==0){ pop(plaka,garage1); push(plaka,temporary); i++; } while(isempty(temporary)!=1){ pop(plaka,temporary); push(plaka,garage1); } temp_pop(plaka,garage3); push(plaka,garage1); return 1; } if(garagenum==2){ i=0; while(strcmp(garage2.plate[i],mystring)==1){ pop(plaka,garage2); push(plaka,temporary); i++; } while(!isempty(temporary)){ pop(plaka,temporary); push(plaka,garage2); } temp_pop(plaka,garage3); push(plaka,garage2); return 1; } if(garagenum==3){ if(findel(garage1,mystring)){ while(strcmp(garage1.plate[i],mystring)==1){ pop(plaka,garage1); push(plaka,temporary); i++; } while(!isempty(temporary)){ pop(plaka,temporary); push(plaka,garage1); } return 1; } if(findel(garage2,mystring)){ while(strcmp(garage2.plate[i],mystring)==1){ pop(plaka,garage2); push(plaka,temporary); i++; } while(!isempty(temporary)){ pop(plaka,temporary); push(plaka,garage2); } return 1; } if(temp_findel(garage3,mystring)){ temp_pop(plaka,garage3); return 1; } if(!temp_findel(garage3,mystring)&&!findel(garage2,mystring)&& !findel(garage1,mystring)) return 0; } } void pop(char *mystring,garage &line){ if(isempty(line)){ cout<<"error,can't pop,stack empty"<<endl; exit(1); } else{ line.top--; mystring=new char[sizeof(line.plate[line.top])/sizeof(char)]; strcpy(mystring,line.plate[line.top]); line.elements--; } } void temp_pop(char *mystring,temp_storage &line){ if(temp_isempty(line)){ cout<<"error,can't pop,stack empty"<<endl; exit(1); } else{ line.temptop--; mystring=new char[sizeof(line.tempplate[line.temptop]) /sizeof(char)]; strcpy(mystring,line.tempplate[line.temptop]); line.tempelements--; } } ---------------------------------------------------------------------------- ---- Do you Yahoo!? Y! Web Hosting - Let the expert host your web site --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.408 / Virus Database: 230 - Release Date: 24/10/02 |
|
From: Per W. <pw...@ia...> - 2002-10-28 19:55:11
|
Well, your questions are still about school assignments, even if you
now have removed any comments to your teachers requirements, but...
Might you tell us how you expected the "mystring" parameter to pop and
temp_pop to actually return anything to the caller? Yes inside your
function, mystring is a variable like everything else. Then you assign a
new pointer to the parameter, and copy a string value to the newly
allocated buffer space.
/Per W
On Mon, 28 Oct 2002, senem beken wrote:
>
> when i try to get the elements back from a function i wrote, i get an error called "access violation" and i don't know what that is.i'd be glad if anyone who has time would look at it...i'm sending one part of the code, the one which doesn't work...
> kind regards...
> int removecar(int garagenum,char *mystring){
> int i=0;
> char plaka[10];
> if(garagenum==1){
> while(strcmp(garage1.plate[i],mystring)==0){
> pop(plaka,garage1);
> push(plaka,temporary);
> i++;
> }
>
> while(isempty(temporary)!=1){
> pop(plaka,temporary);
> push(plaka,garage1);
> }
> temp_pop(plaka,garage3);
> push(plaka,garage1);
> return 1;
> }
> if(garagenum==2){
> i=0;
> while(strcmp(garage2.plate[i],mystring)==1){
> pop(plaka,garage2);
> push(plaka,temporary);
> i++;
> }
>
> while(!isempty(temporary)){
> pop(plaka,temporary);
> push(plaka,garage2);
> }
> temp_pop(plaka,garage3);
> push(plaka,garage2);
> return 1;
> }
> if(garagenum==3){
> if(findel(garage1,mystring)){
> while(strcmp(garage1.plate[i],mystring)==1){
> pop(plaka,garage1);
> push(plaka,temporary);
> i++;
> }
>
> while(!isempty(temporary)){
> pop(plaka,temporary);
> push(plaka,garage1);
> }
> return 1;
> }
> if(findel(garage2,mystring)){
> while(strcmp(garage2.plate[i],mystring)==1){
> pop(plaka,garage2);
> push(plaka,temporary);
> i++;
> }
>
> while(!isempty(temporary)){
> pop(plaka,temporary);
> push(plaka,garage2);
> }
> return 1;
> }
> if(temp_findel(garage3,mystring)){
> temp_pop(plaka,garage3);
> return 1;
> }
> if(!temp_findel(garage3,mystring)&&!findel(garage2,mystring)&&
> !findel(garage1,mystring))
>
> return 0;
> }
> }
>
> void pop(char *mystring,garage &line){
> if(isempty(line)){
> cout<<"error,can't pop,stack empty"<<endl;
> exit(1);
> }
> else{
> line.top--;
> mystring=new char[sizeof(line.plate[line.top])/sizeof(char)];
> strcpy(mystring,line.plate[line.top]);
> line.elements--;
> }
> }
> void temp_pop(char *mystring,temp_storage &line){
> if(temp_isempty(line)){
> cout<<"error,can't pop,stack empty"<<endl;
> exit(1);
> }
> else{
> line.temptop--;
> mystring=new char[sizeof(line.tempplate[line.temptop])
> /sizeof(char)];
> strcpy(mystring,line.tempplate[line.temptop]);
> line.tempelements--;
> }
> }
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Y! Web Hosting - Let the expert host your web site
|