Sponsored Content
Full Discussion: Constructor?
Top Forums Programming Constructor? Post 302776453 by Corona688 on Wednesday 6th of March 2013 11:01:17 AM
Old 03-06-2013
It is a function that is run whenever an object is created. It has the same name as the class.

The opposite is the destructor, which is run whenever an object is deleted. It's the same name as the class with a ~ before it.

Code:
#include <iostream>
using namespace std;

class myclass
{
public:
        myclass() {
                cout <<"Someone created a myclass object\n";
        }

        ~myclass() {
                cout <<"Someone removed a myclass object\n";
        }
};

int main(void)
{
        myclass obj;
}

 

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Constructor problem

Hi guys I am new to these forums but since I am taking a class at college I would appreciate any help that is possible for this program. My instructor said that when its complete the program should be able to store all 3 fields instead of just 1. public class Greeter2Test { public static... (4 Replies)
Discussion started by: woot4moo
4 Replies

2. Programming

why constructor cannot be virtual

helo i read many books but i cant find the proper answer that why constructor cannot be virtual can u explain me in simple term that why constructor cannot be virtual Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

3. Programming

how do you handle a constructor and destructor that fail

helo i m new in c++ on linux can u tell me with an simple example that how do you handle constructor and destructor that fail? Regards, Amit (4 Replies)
Discussion started by: amitpansuria
4 Replies

4. Programming

Doubt regarding Copy Constructor and return value

Hi All, I have made the simple following program :- #include <string> #include <iostream> using namespace std; class A{ private: int val; public : A(){cout<<"In A()"<<endl;} A (const A& aa) { cout<<"In copy c'tor"<<endl; } }; A f(... (1 Reply)
Discussion started by: shubhranshu
1 Replies

5. Programming

c++ object constructor question

I have the following code class Param{ public: Param(int aa, int bb){ a=aa; b=bb; } int a,b; }; void function(Param); int main(){ function(2,3); return 0; } (6 Replies)
Discussion started by: santiagorf
6 Replies

6. Programming

Doubts on C++ copy constructor concept

Hi, If I run the following program class A { public: A() { cout << "default" << endl; } A(const A&) { cout << "copy" << endl; } }; A tmp; A fun() { return tmp; } A test() { A tmp; cout << &tmp << endl; return tmp; } (1 Reply)
Discussion started by: royalibrahim
1 Replies
QwtIntervalSample(3)						 Qwt User's Guide					      QwtIntervalSample(3)

NAME
QwtIntervalSample - A sample of the types (x1-x2, y) or (x, y1-y2) SYNOPSIS
#include <qwt_series_data.h> Public Member Functions QwtIntervalSample () QwtIntervalSample (double, const QwtInterval &) QwtIntervalSample (double value, double min, double max) bool operator== (const QwtIntervalSample &) const bool operator!= (const QwtIntervalSample &) const Public Attributes double value QwtInterval interval Detailed Description A sample of the types (x1-x2, y) or (x, y1-y2) Constructor &; Destructor Documentation QwtIntervalSample::QwtIntervalSample () [inline] Constructor The value is set to 0.0, the interval is invalid QwtIntervalSample::QwtIntervalSample (doublev, const QwtInterval &intv) [inline] Constructor. QwtIntervalSample::QwtIntervalSample (doublevalue, doublemin, doublemax) [inline] Constructor. Member Function Documentation bool QwtIntervalSample::operator!= (const QwtIntervalSample &other) const [inline] Compare operator. bool QwtIntervalSample::operator== (const QwtIntervalSample &other) const [inline] Compare operator. Member Data Documentation QwtInterval QwtIntervalSample::interval Interval. double QwtIntervalSample::value Value. Author Generated automatically by Doxygen for Qwt User's Guide from the source code. Version 6.0.0 Fri Apr 15 2011 QwtIntervalSample(3)
All times are GMT -4. The time now is 04:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy