Solved

how can i declare Classes  in c++

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 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