Solved

how can i declare Classes  in c++

Posted on 2000-04-22
3
243 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 100 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

820 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