Register for your free account! | Forgot your password?

You last visited: Today at 08:57

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



struct and classes

Discussion on struct and classes within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2012
Posts: 34
Received Thanks: 2
struct and classes

took about 50 pages reading about difference between structs and classes , so i thought it's good idea to sum up this for whoever want to get it with a spoon , feel free to correct or add information

at struct cannot have instance field initializers in structs
Code:
    struct time
    {
        private int x = 5; // compile-time error        
    }
Structs cannot contain explicit parameterless constructors
Code:
    struct time
    {
        private time() // compile-time error
        {
        }
    }
at struct all Fields must be fully assigned before control is returned to the caller
Code:
    struct time
    {
        private int x; // compile-time error
        public time(int a)
        {
        }
    }
struct is value type and class is ref. type

struct use values so it's in stack but type use ref so it's in heap

can't declare a defualt constructor at struct but u can at class

at struct it will generate a default const. for u even if u got one but it won't at class

struct won't intialize a field for u at ur constructor but class will

at struct you are not allowed to initialize instance fields at there point of decleration(but u still need to assigned value to it before it return to the caller) but u can at class

Code:
struct time
    {
        private int x = 10; // compile-time error
    }
what i said doesn't cover inheritance , please feel free to tell me why should i use one and not the other while codding something

one more info
at struct you can declare a field witout new keyword (as struct is values) but once u try to access it , it will just give an error , but with new keyword you declare them with defualt values aka 0 , false and null , here is an example

Code:
class Program
    {
        static void Main(string[] args)
        {
            time now ;
            Console.WriteLine(now.hr); // compile-time error
        }

    }

    struct time
    {
        public int hr, min, sec;
    }
Code:
class Program
    {
        static void Main(string[] args)
        {
            time now = new time();
            Console.WriteLine(now.hr); // no errors , result is 0
        }

    }

    struct time
    {
        public int hr, min, sec;
    }
at both cases the time feild (variable) will be created on stack but at the first it will be left in their uninitialized state and any attempt to access them will result to compile-time error

if u found it helpful lemme know to give it a try at arrays and collections , im reading tons of pages and sum up for my self in lines as refrence and got no problem to share them with u
Mind Fuck is offline  
Old 08/02/2012, 08:46   #2
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
**** I'm dumb. I was about to sum up the errors in your thread and I realize it was a tutorial.
I don't have a username is offline  
Old 08/02/2012, 08:54   #3
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
You should probably actually learn what you're trying to write a tutorial about before writing a tutorial about....
InfamousNoone is offline  
Old 08/02/2012, 11:12   #4
 
elite*gold: 0
Join Date: Jul 2012
Posts: 34
Received Thanks: 2
Quote:
You should probably actually learn what you're trying to write a tutorial about before writing a tutorial about....
so that was horrible ?
Mind Fuck is offline  
Old 08/02/2012, 11:26   #5
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
provides more insight than your post.
InfamousNoone is offline  
Old 08/02/2012, 11:52   #6
 
elite*gold: 0
Join Date: Jul 2012
Posts: 34
Received Thanks: 2
i wasn't explaining the struct and classes ? , i was pointing out some difference between them and i assume who read this already knows about struct and classes
anyway thanks for the feed back
Mind Fuck is offline  
Old 08/03/2012, 00:11   #7
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
If they already know about them, why wouldn't you assume they know the differences between them...? lol.
Secondly, you never mention why certain limitations are imposed onto structs, you just say "here is the difference": (example) -- which is useless.
InfamousNoone is offline  
Reply


Similar Threads Similar Threads
Action Struct (Walking) - What am I doing wrong?
05/06/2012 - Perfect World - 4 Replies
Fixed.
[Introduction] Carlyle Struct Manager
09/28/2011 - Flyff Private Server - 9 Replies
Hello guys, I've been working on a program that allows you to convert, export, import all Flyff file extensions. I will release this when I´m finished. I´m not releasing the source code until I think that it is gonna be usefull for somebody. The programm is written in C# 2010. Currently I´m working on the model file structure. http://s7.directupload.net/images/110927/9vpehr25 .jpg
[c++] struct
08/25/2011 - C/C++ - 2 Replies
Kann closed werden. sry
C++ Fragen | Arrays & struct
06/16/2011 - C/C++ - 3 Replies
Und zwar habe ich 2 Fragen! Arrays: -------------------------------- struct:
habt ihr die metin2 player struct?
07/05/2009 - Metin2 - 12 Replies
hi leute, mich würds interessieren, ob ihr hier die player struct kennt? also den aufbau. falls nicht, würde ich gerne wissen wie ihr die umgebung auslest.. falls ihr das überhaupt irgendwo macht ;). gruß wadim



All times are GMT +1. The time now is 09:01.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.