Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how can i declare Classes  in c++

Posted on 2000-04-22
3
Medium Priority
?
249 Views
Last Modified: 2010-04-02
classes in c++ it introduction to "oop"
then i need program using class.
and what mian of consturcter and destructer?
mianing vertiul;
sen a full programme to explian  this way.
0
Comment
Question by:fathikhid
3 Comments
 
LVL 5

Expert Comment

by:laeuchli
ID: 2740111
sorry, we are not allowed to do school project.
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2740693
you see we don't do homework but i"ll explain a little that you"ll understand the idea

class structure:

class name_of_the_class{
private:
//here goes the private data members
//and the private methods mostlly data
//members
public:
//here goes the public data members
//and the public methods mostlly methods
//and the c'tors and the d'tors
};

now the idea of the c'tor is to updata the class data members with data at the creation of the class like
class myclass{
private:
int x;
public:
myclass(int x1){
x=x1;
}
then in main
myclass class1(1);
//it will create a class named class1 //type of myclass when the x paramter
//will be 1 <x=1>

//the d'tor used to free memory when
//class is distoried it used to free
//dynamic allocated memroy using the
//funcs delete or delete[]

i hope you got the idea now you"ll have to do the rest by yourself

0
 

Accepted Solution

by:
rkcth earned 300 total points
ID: 2740752
class myclass
{
public:
void myclass();
void ~myclass();
}

myclass::myclass()
{
//code for constructor goes here
}

myclass::~myclass()
{
//code for destructor goes here
}

constuctors are called whenever someone makes a variable of your class type. Destructors are called when it is destroyed.
Hope this helps.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question