Jump to content

Recommended Posts

Posted
#include<iostream>

using namespace std;

class dnd

{

public:

	int a;

	dnd(int b=0); //constructor

};

dnd::dnd(int b)

{

	cout<<"valoarea data este: "<<b;

}

dnd h; //declaram un obiect de tip dnd

int main()

{

	dnd x(6), y=122, z; //pentru z se apeleaza constuctorul implicit, si anume cu valoarea 0

	system("PAUSE");

	return 0;

}

  • 4 weeks later...

Posted

sigur merge? Am invatat ca in momentu in care ai un constructor, cel implicit nu mai e creat, si ar trebui sa deie eroare la compilare..

app, cei cu b=0 ca parametru?

love is a verb
Love is a doing word

Posted

Depinde de care constructor ai declarat. Dar dnd(int b=0) e un constructor implicit declarat de noi..deci ptr z, se initializeaza cu 0 asta..putea fi si alta valoare nu neaparat 0.

Puteai avea dnd(int b) { b=0; }..e mai "mult" de scris =))

Posted

Bn hai ca scriu detaliat, poate asa intelegi: dnd() { b=0; } dnd(int x) { b=x; } mai trage cu ochiul si la tutorialele de pe net, gen: IBM, cdplusplus...ps: sunt cateva in lb.rom. Dar cu erori, nu mai stiu care...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.