-
class constructor question
I got this code:
Code:
#include <iostream>
using namespace std;
class test
{
private:
int y;
public:
int z;
test(test object)
{
y=object.z;
}
void print_y();
};
void test::print_y()
{
cout<<y<<endl;
}
int main()
{
test ob2;
cout<<"Put whatever you want";
cin>>ob2.z;
test ob1(ob2);
ob1.print_y();
}
I got dozens of errors like "You should use const test &". I think everything is correct with the code. why i got those errors?
Thanks in advance.
Regards.
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
I think everything is correct with the code.
Obviously it's not.
First, you can't pass test by-value in your copy constructor. Think about it, the reason should be quite obvious (HINT: what happens when you pass something by-value?).
Second, you'll need to explicitly define a default constructor in addition to your (broken) copy constructor.
Third, this rubbish interface can be easily replaced by providing an appropriate operator>> overload.
-
Re: class constructor question
If I pass by-value then there is copy of the variable (in this case object of the class test), and then if in int main(), I input ob2.z=5, it should pass it on y=5. I can't see reason to use pass by reference?
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
If I pass by-value then there is copy of the variable (in this case object of the class test), and then if in int main(), I input ob2.z=5, it should pass it on y=5. I can't see reason to use pass by reference?
Sigh... Let's try this again.
What gets invoked when you pass by-value?
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
If I pass by-value then there is copy of the variable (in this case object of the class test), and then if in int main(), I input ob2.z=5, it should pass it on y=5. I can't see reason to use pass by reference?
and where do you magically get your copy from?
-
Re: class constructor question
There is copy created of the ob2. I should use pass by reference if I alter the ob1 variables but I don't alter them.
For example if I need to change something in the object
Function1(test &ob1)
{
ob1.z=5;
}
or something like that.
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
There is copy created of the ob2. I should use pass by reference if I alter the ob1 variables but I don't alter them.
For example if I need to change something in the object
Function1(test &ob1)
{
ob1.z=5;
}
or something like that.
You're missing the ****ing point.
When you pass T by-value, T's copy constructor gets invoked. In your case, over and over and over. In short, impossible. Passing T by (const) reference alleviates that problem.
If you don't understand this simple concept, perhaps you should stick with shallow copying for now. Besides, that snippet in your OP doesn't require an explicit copy constructor in the first place. :sick:
-
Re: class constructor question
Quote:
Originally Posted by StGuru
I should use pass by reference if I alter the ob1 variables but I don't alter them.
There is another reason to use pass by reference: to avoid copying the object. If you do not want to modify the object through the reference then pass by const reference.
Quote:
Originally Posted by StGuru
There is copy created of the ob2.
Indeed. And the act of copying invokes the copy constructor, which happens to be precisely what you are trying to implement. So what you are saying is this: I want to copy the object in order to implement copying of the object. That does not make sense.
-
Re: class constructor question
@Plasmator, I understand what are u saying to me, but I got copy of ob2, which doesn't got constructor.
Even if I put
Code:
#include <iostream>
using namespace std;
class test
{
private:
int y;
public:
int z;
test()
{
y=1;
}
test(test object)
{
y=object.z;
}
void print_y();
};
void test::print_y()
{
cout<<y<<endl;
}
int main()
{
test ob2;
cout<<"Put whatever you want";
cin>>ob2.z;
test ob1(ob2);
ob1.print_y();
}
the copy would invoke parametrized constructor and initialize y=1. I don't see a problem.
-
Re: class constructor question
You're passing ob2 to the copy constructor by-value.
To pass by value the compiler uses the copy constructor, which copies its parameter by value...
So the compiler uses the copy constructor, which copies its parameter by value...
So the compiler uses the copy constructor, which copies its parameter by value...
etc. etc. until something breaks.
-
Re: class constructor question
Quote:
Originally Posted by StGuru
I got copy of ob2, which doesn't got constructor
obj2 is default constructed.
Quote:
Originally Posted by StGuru
the copy would invoke parametrized constructor and initialize y=1. I don't see a problem.
How did you manage to come to that conclusion?
Look, I think you are sorely in need of an example:
Code:
#include <iostream>
class X
{
public:
X()
{
std::cout << "default constructor invoked" << std::endl;
}
X(const X&)
{
std::cout << "copy constructor invoked" << std::endl;
}
X& operator=(const X&)
{
std::cout << "copy assignment operator invoked" << std::endl;
return *this;
}
~X()
{
std::cout << "destructor invoked" << std::endl;
}
};
int main()
{
X a;
X b(a);
X c;
c = a;
}
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
@Plasmator, I understand what are u saying to me, but I got copy of ob2, which doesn't got constructor.I don't see a problem.
Quote:
Originally Posted by
Plasmator
When you pass T by-value, T's copy constructor gets invoked. In your case, over and over and over. In short, impossible. Passing T by (const) reference alleviates that problem.
JohnW@Wessex's getting at the same thing.
-
Re: class constructor question
ok, now I am totaly confused. When the object is declared then the constructor is invoked.
Now when ob1(ob2) the constructor:
test(test ob2)
{
y=object.z;
}
the constructor will create copy of ob2, which will invoke another unparametrized constructor in this case my constructor is:
test()
{
y=1;
}
It is like I create two separate objects. I don't know why u say that the process is infinite.
-
Re: class constructor question
Quote:
Originally Posted by StGuru
the constructor will create copy of ob2, which will invoke another unparametrized constructor in this case my constructor is:
It won't. Logically, the act of copying invokes this constructor:
Code:
test(test ob2)
{
y=object.z;
}
-
Re: class constructor question
Why that constructor, when I got other unparamterized?
Why in this code when I pass by value, there isnt invoking of the constructor of class B?
Code:
#include <iostream>
using namespace std;
class B
{
public:
B()
{
cout<<"test";
}
int n;
};
class test
{
private:
int y;
public:
int z;
test()
{
y=1;
}
test(B object)
{
y=object.n;
}
void print_y();
};
void test::print_y()
{
cout<<y<<endl;
}
int main()
{
B ob2;
B ob3;
cout<<"Put whatever you want";
cin>>ob2.n;
test ob1(ob2);
ob1.print_y();
system("PAUSE");
}
-
Re: class constructor question
EDIT:
Quote:
Originally Posted by StGuru
Why that constructor, when I got other unparamterized?
Why not that constructor, when that constructor's signature is a match?
Quote:
Originally Posted by StGuru
Why in this code when I pass by value, there isnt invoking of the constructor of class B?
The copy constructor of B is invoked. Since no copy constructor is declared, the compiler defines it for you.
-
Re: class constructor question
Why it must be parametrized so that the copy of the object would invoke the constructor?
Is that by default?
-
Re: class constructor question
Quote:
Originally Posted by StGuru
Why it must be parametrized so that the copy of the object would invoke the constructor?
Back to the basics:
Code:
#include <iostream>
void foo()
{
std::cout << "hello" << std::endl;
}
void foo(int n)
{
std::cout << n << std::endl;
}
int main()
{
foo(123);
}
I think that the output should involve "hello" because the function foo is called. Do you agree?
-
Re: class constructor question
I totally agree. It is same with the objects. The constructor that is called depends from the arguments that it has.
Here:
Code:
#include <iostream>
using namespace std;
class B
{
public:
B()
{
cout<<"test";
}
int n;
};
class test
{
private:
int y;
public:
int z;
test()
{
y=1;
}
test(B object)
{
y=object.n;
}
void print_y();
};
void test::print_y()
{
cout<<y<<endl;
}
int main()
{
B ob2;
B ob3;
cout<<"Put whatever you want";
cin>>ob2.n;
test ob1(ob2);
ob1.print_y();
system("PAUSE");
}
test ob1(ob2);
The constructor
test(B object)
{
y=object.n;
}
is invoked because of the argument ob2.
Now there is copy of ob2, which is object from the class B. I asked when this object is created, which constructor is invoked, the parametrized or parametrized and why (since I never stated each of them to be invoked with the creation of the copy) ?
Thanks in advance.
-
Re: class constructor question
Quote:
Originally Posted by StGuru
I asked when this object is created, which constructor is invoked, the parametrized or parametrized and why (since I never stated each of them to be invoked with the creation of the copy) ?
It has to be parameterised, since you are invoking the copy constructor to make a copy of what you passed as an argument.
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
Now there is copy of ob2, which is object from the class B. I asked when this object is created,
Which object? The B object?
Let's take this one step at a time:
1) You created a test object with a single parameter, which is a B object. So the constructor for test that takes a B object is invoked.
2) Since you passed by-value a B object to the test constructor, the compiler automatically generates a copy of the B object. For the compiler to generate a copy of the B object, the B object's copy constructor is called. Since you didn't provide a user-defined copy constructor for B, the compiler generated version of the copy constructor for B is invoked instead.
So you have two objects being created with that single line of code:
You have one "test" object, and a temporary "B" object being created.
Also note that copy construction can be removed by the compiler if it is detected that the copy is superfluous -- another wrinkle in this whole scenario. But in general, steps 1) and 2) is what is being done.
Regards,
Paul McKenzie
-
Re: class constructor question
Thanks for the replies. I understand what are u saying to me. But I don't understand why it has to be parametrized. I got another nonparametric in the object B. Why it is not called, when there is not another constructor?
-
Re: class constructor question
Quote:
Originally Posted by StGuru
I got another nonparametric in the object B. Why it is not called, when there is not another constructor?
1. The default constructor is not called because its signature does not match in any way.
2. The compiler generates a copy constructor for you if necessary.
-
Re: class constructor question
And what does that constructor do (which is created by compiler)?
What if I write:
B(int y)
{
cout<<"test";
}
would the copy of object invoke this constructor( I tried and it didn't, but why)?
test(B object)
{
y=object.n;
}
-
Re: class constructor question
Quote:
Originally Posted by StGuru
And what does that constructor do (which is created by compiler)?
It performs "shallow" copying of the object's member variables (and base class subobjects).
Quote:
Originally Posted by StGuru
would the copy of object invoke this constructor( I tried and it didn't, but why)?
Why would it? A constructor that takes an int argument is not a copy constructor.
-
Re: class constructor question
Oh, I see now what are you saying to me. I thought that with the creation of new object there will be invoked constructor which is inside the class (the same like declaring object and invoking constructor). I didn't know that there is copy constructor which creates new object. And what if I write my own copy-constructor like this:
B(const B &object)
{
cout<<"test";
}
Would then will be created copies of the object's member variables?
test(B object)
{
y=object.n;
}
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
Code:
#include <iostream>
using namespace std;
class test
{
private:
int y;
public:
int z;
test()
{
y=1;
}
test(test object)
{
y=object.z;
}
void print_y();
};
void test::print_y()
{
cout<<y<<endl;
}
int main()
{
test ob2;
cout<<"Put whatever you want";
cin>>ob2.z;
test ob1(ob2);
ob1.print_y();
}
Hehe, we're having a match of guru's national sport here. All trying to make u get it. Okay lemme join in :D
1st: StGuru, try to accept the idea that your C++ compiler is not bugged, but just rightfully complaining about the code input to it.
Here is my approach :)
say you are the programmer, and I am the compiler. Now let's inspect your code from the main() function line by line.
you say: test ob2;
I say: very good, I shall instantiate an object of type 'test' on main() local stack. It looks like the programmer has not specified any constructor for his object named 'ob2', so I shall just invoke the default (e.g. without arguments) constructor. I don't care if my programmer has specifically defined one or not, because if he didn't, I shall define it by default. However, in this scenario there is one such constructor defined explicitly by programmer.
you say: cout<<"Put whatever you want"; cin>>ob2.z;
I say: .. not really important what I say, I just do what you wanted to do here
you say: test ob1(ob2);
I say: (inside main() - excellent, another object of type 'test'. And my programmer would like me to use another constructor for this one, and I dont care if it is defined or not, because if it isn't I shall define a default copy constructor (i.e. with one 'test' argument). However in this scenario, I do have a copy constructor defined by programmer
I say: (in test(test object)) - Ok, so I shall just proceed along and carry on the instantiation of 'ob1'. Let me see now ... the arguments passed is of ... type .. 'test'. And it is a very vivid (valid and instantiated) argument this one u have passed - 'ob2'. Only one tiny problem, 'ob2' is valid and instantiated in the context of function main (i.e. on main()'s stack. I do not have any idea of what this parameter might be on the current (i.e. on test(test object)'s stack. But I can fix it, I shall just copy the value of 'ob2' from inside main() function into another variable, this time local to me, and carry on. I other words, the 'ob2' that is supposed to get inside of test(object test) is not the same thing with 'ob2' from main()'s tack. So I have to make a copy of this ob2 as I have said, and how to do that other than ... well ... invoking once again the copy constructor, so:
I say: (in test(test object) {2} ) - Ok, so I shall just proceed along and carry on the instantiation of 'ob1'. Let me see now ... the arguments passed is of ... type .. 'test'. And it is a very vivid (valid and instantiated) argument this..... ET CETERA
Now, what if the copy constructor was test(test* object) or test(test& object) - the compiler would have checked to see if it has access to the 'ob2' defined inide main() only this time it would conclude that yes, it does, so no copy constructor is needed. It would just use the same 'ob2' as the one in main. Full stop. End of story.
Do I get a beer ?
B)
-
Re: class constructor question
**** it! It took me 32 minutes+ to rite the previous post, and U have figured it out ....
-
Re: class constructor question
kellogs it helped me. Thank you very much for the help. I own u beer! :-). What I can't understand now is, will the same do
B(const B &object)
{
cout<<"test";
}
or it will not create object and will print test?
-
Re: class constructor question
Quote:
Originally Posted by StGuru
What I can't understand now is, will the same do
B(const B &object)
{
cout<<"test";
}
or it will not create object and will print test?
No copying is involved since the parameter is a const reference.
-
Re: class constructor question
I mean:
Code:
#include <iostream>
using namespace std;
class B
{
public:
B()
{
cout<<"test";
}
int n;
};
class test
{
private:
int y;
public:
int z;
test()
{
y=1;
}
test(B object)
{
y=object.n;
}
void print_y();
};
void test::print_y()
{
cout<<y<<endl;
}
int main()
{
B ob2;
B ob3;
cout<<"Put whatever you want";
cin>>ob2.n;
test ob1(ob2);
ob1.print_y();
system("PAUSE");
}
Here I got a copy of the object, and a copy constructor. Will be there copy of the object?
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
Here I got a copy of the object, and a copy constructor.
First, can you please format your code a little better? It is very hard to read when it's staggered all over the place.
Second, you do not have a user-defined copy constructor. You have a default constructor, not a uder-defined copy constructor.
A copy constructor has the following prototype:
There are other signatures that are valid copy constructors, but this is the one that is mainly used. All of them require a reference to a B object as the parameter.
Regards,
Paul McKenzie
-
Re: class constructor question
Sorry, I put the wrong code. Here is the new one:
Code:
#include <iostream>
using namespace std;
class B
{
public:
B(const B &object)
{
cout<<"test";
}
int n;
};
class test
{
private:
int y;
public:
int z;
test()
{
y=1;
}
test(B object)
{
y=object.n;
}
void print_y();
};
void test::print_y()
{
cout<<y<<endl;
}
int main()
{
B ob2(ob2);
B ob3(ob3);
cout<<"Put whatever you want";
cin>>ob2.n;
test ob1(ob2);
ob1.print_y();
system("PAUSE");
}
-
Re: class constructor question
StGuru, please put in more effort to indent and format your code properly. For example:
Code:
#include <iostream>
using namespace std;
class B
{
public:
B(const B &object)
{
cout << "test";
}
int n;
};
class test
{
public:
int z;
test()
{
y = 1;
}
test(B object)
{
y = object.n;
}
void print_y();
private:
int y;
};
void test::print_y()
{
cout << y << endl;
}
int main()
{
B ob2(ob2);
B ob3(ob3);
cout << "Put whatever you want";
cin >> ob2.n;
test ob1(ob2);
ob1.print_y();
system("PAUSE");
}
Note that you should #include <cstdlib> for std::system(), but it is not necessary anyway.
So, what is your question again?
-
Re: class constructor question
Will be there copy of the object since I defined my own copy constructor just to print "test"?
-
Re: class constructor question
Quote:
Originally Posted by StGuru
Will be there copy of the object since I defined my own copy constructor just to print "test"?
Yes, unless the compiler is able to elide (as in remove) the copying. Whether the copying is correct is another matter.
By the way, I am not sure what to make of this:
Code:
B ob2(ob2);
B ob3(ob3);
You don't need ob3 in your example, and you should default construct ob2. You need to define the default constructor since you have declared the copy constructor (the default constructor is only generated by the compiler when there are no user declared constructors).
-
Re: class constructor question
Your right about the objects/ I just need to define default constructor.
Anyway, my copy constructor should copy the object. For example:
//=== file Point.h =============================================
class Point {
public:
. . .
Point(const Point& p); // copy constructor
. . .
//=== file Point.cpp ==========================================
. . .
Point::Point(const Point& p) {
x = p.x;
y = p.y;
}
. . .
//=== file my_program.cpp ====================================
. . .
Point p; // calls default constructor
Point s = p; // calls copy constructor.
p = s; // assignment, not copy constructor.
would copy the variables of the object. And in my case it would just print "test". That's what I am asking.
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
And in my case it would just print "test". That's what I am asking.
Hopefully this is just an exercise. When you take on the responsibility of writing your own copy constructor, you better be telling the truth to the compiler -- you are actually making a valid copy of the object. You are not doing that in your copy constructor, since you had a variable "n" that was never copied.
If you don't do this, what you'll end up with are two objects, where one is a partial or bogus copy of the other. What ends up happening is that at runtime, you are susceptible to errors that are very difficult to spot. Basically the rule to follow is this:
You have two objects, A and B, and B is a copy of A. Wherever in the program I use A, if I replace A with B, the program must show the same exact behaviour. If using B results in different behaviour than A, then you don't have a copy, and you're attempting to shoot yourself in the foot.
Secondly, you only code a user-defined copy constructor when you have to. According to your class, the default copy constructor generated by the compiler is adequate and you need not write your own copy constructor. Again, if you're wrong in the way you've coded your copy constructor, the compiler will not warn you. So if you don't need to write a user-defined copy constructor, don't write one.
Regards,
Paul McKenzie
-
Re: class constructor question
Thanks for the replies.
And how does the copy constructor looks like in the compiler?
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
Thanks for the replies.
And how does the copy constructor looks like in the compiler?
It depends on the compiler and the members that are to be copied.
Regards,
Paul McKenzie
-
Re: class constructor question
Quote:
Originally Posted by
StGuru
Your right about the objects/ I just need to define default constructor.
Point p; // calls default constructor
Point s = p; // calls copy constructor.
p = s; // assignment, not copy constructor.
would copy the variables of the object. And in my case it would just print "test". That's what I am asking.
dude ...
first line: ok
second line NOT OK. 'Point s' just calls the default, argumentless constructor, then the following 's = p' calls operator=. Copy constructor is called when 'Point s(p)'
third line: ok
Quote:
Originally Posted by
StGuru
kellogs it helped me. Thank you very much for the help. I own u beer! :-). What I can't understand now is, will the same do
B(const B &object)
{
cout<<"test";
}
or it will not create object and will print test?
Ok u give me the beer! ^^
But I am not conviced of ur understanding. Say why dont u read some good programin' book or tutorial ? Cant recommend u onne though on the spot. Maybe others .
Cheers
-
Re: class constructor question
Quote:
Originally Posted by kellogs
second line NOT OK. 'Point s' just calls the default, argumentless constructor, then the following 's = p' calls operator=. Copy constructor is called when 'Point s(p)'
Actually, StGuru is correct. The second line invokes the copy constructor, not the default constructor and copy assignment operator.
-
Re: class constructor question
Quote:
Originally Posted by
laserlight
Actually, StGuru is correct. The second line invokes the copy constructor, not the default constructor and copy assignment operator.
I'll be, tested it, StGuru was correct indeed. Okay I shall pass the beer from StGuru along, laserlight
-
Re: class constructor question
I was doing a little research and find out when:
I - When an object is created from another object of the same type if I define the copy constructor as (for ex. test ob=ob1):
Code:
test(const test &objekat)
{
cout<<"Copy constructor is called."<<endl;
}
the values of ob1 would not be copied to ob and "Copy constructor is called." would be printed.
II - When an object is passed by value as a parameter to a function and the copy constructor defined as:
Code:
test(const test &objekat)
{
cout<<"Copy constructor is called."<<endl;
}
then the members of the class would be copied (no matter what is defined in the copy constructor) and "Copy constructor is called." would be printed.
-
Re: class constructor question
That is interesting. This difference does not sound correct to me, and a quick check with g++ 4.2.4 (with and without optimisations turned on) for this test program:
Code:
#include <iostream>
#include <string>
class X
{
public:
explicit X(const std::string s = std::string()) : s(s) {}
X(const X& other)
{
std::cout << "X copy ctor" << std::endl;
}
std::string get() const
{
return s;
}
private:
std::string s;
};
void foo(X x)
{
std::cout << x.get() << std::endl;
}
int main()
{
X a("test");
std::cout << "Test #1: " << std::endl;
X b = a;
std::cout << b.get() << std::endl;
std::cout << "Test #2: " << std::endl;
foo(a);
}
gives me the output of:
Code:
Test #1:
X copy ctor
Test #2:
X copy ctor
Changing the copy constructor implementation to:
Code:
X(const X& other) : s(other.s)
{
std::cout << "X copy ctor" << std::endl;
}
gave me the output of:
Code:
Test #1:
X copy ctor
test
Test #2:
X copy ctor
test
Either way, I did not detect the difference that you described.
-
Re: class constructor question
Here is the code that I worked with:
Code:
#include <iostream>
using namespace std;
class test
{
int c;
friend void funkcija(test);
public:
int d;
test(){ cout<<"Unparametrized constructor."<<endl;}
test(const test &objekat)
{
cout<<"Copy constructor called."<<endl;
}
};
void funkcija(test objekat){
cout<<objekat.c<<endl;
cout<<objekat.d;
}
int main()
{
test ob;
funkcija(ob);
system("PAUSE");
return 0;
}
The copy constructor is made to make deep copy of the object. So to make sure that the members of the class test (c,d) exist I printed their values in the function (no matter the printed text is non-understandable, I can still change their values (for ex. object.c=5 or object.d=33) so they obviously exist.
-
Re: class constructor question
Quote:
Originally Posted by StGuru
So to make sure that the members of the class test (c,d) exist I printed their values in the function (no matter the printed text is non-understandable, I can still change their values (for ex. object.c=5 or object.d=33) so they obviously exist.
Then show an example where you actually initialise the member variable (only d, since you cannot initialise c from the main function), then in foo the member variable is correctly copied despite the lack of a correct implementation of the copy constructor.
Looking at the lack of initialisation, my guess is that you are mistaken: the member variables are not being copied, but you fooled yourself into believing they were copied.
-
Re: class constructor question
Quote:
Originally Posted by
laserlight
Then show an example where you actually initialise the member variable (only d, since you cannot initialise c from the main function), then in foo the member variable is correctly copied despite the lack of a correct implementation of the copy constructor.
Looking at the lack of initialisation, my guess is that you are mistaken: the member variables are not being copied, but you fooled yourself into believing they were copied.
Actually, you're right. I misunderstood the terms 'copy' and 'create' :-).
I got an interesting problem.
Code:
test func(test object)
{
return object;
}
test ob=func(ob1);
We got several callings of the copy constructor.
I - object is passed by value as a parameter to a function
II - object is returned from a function
III- object is created from another object of the same type
But why the copy constructor of test ob=func(ob1); is called first, where there is nothing to copy?
-
Re: class constructor question
Quote:
Originally Posted by StGuru
But why the copy constructor of test ob=func(ob1); is called first, where there is nothing to copy?
What do you mean? Once again, I suggest that you post a small and simple compilable program that demonstrates what you are talking about. Post the output you get as well, keeping in mind that the compiler may elide copy construction in some cases.
-
Re: class constructor question
Thanks for the suggestions. Here is the code:
Code:
#include <iostream>
using namespace std;
class test
{
int c;
friend test funkcija(test);
public:
test(){ cout<<"Non-parametric constructor called."<<endl;}
test(const test &objekat)
{
cout<<"Copy constructor called."<<endl;
}
int d;
};
test funkcija(test objekat)
{ return objekat; }
int main()
{
test ob;
ob.d=5;
test ob1=funkcija(ob);
system("PAUSE");
return 0;
}