Original Post
i have recently purchased a book updated book on c++
the book stated that this.
Point3d test;
test = Point3d(1,1,1); //this is an assisment
i thought that was a reconstruction.
quote:
Original post by Miserable
It is clearly an assignment; you are assigning a new value to the variable test by means of (its) Point3d.operator=(). I am curious, however, as I have never before heard of the term ''reconstruction'': What do you mean by that?
quote:
Original post by sage2003
i assumed that once the default constructor was used to construct test doing this ( test = Point3d(1,1,1) ) would be tring to reconstruct the object test.
quote:
i say this because futher in the book on effecient programing
the auther stated that dealing with large class objects such as
a matrix and given an example of this class with the defined overloaded operators for addition subtraction etc and optimizations made to c++ that this
matrix MatrixAdd(paramList)
{
matrix result;
//do work
return result
}
would be rewritten to
void matrixAdd(matrix &result,paramList)
{
//directly compute into result
{
/////please remember this is just for example
quote:
and so doing this
Matrix test2; //default construct
test2 = test3 + test4;
would invoke your defined operator and the compiler would rewrite
matrix operator+(paramList);
to this
void operator+(test2,paramList);
because the first thing done to the object (test2) is to applied the constructor that has been applied to the local object.The author stated that test2 should not be allready
constructed and so this would construct the object test2 a second
time.
quote:
if that is so then the orginal post or this
matrix test2;
test2 = matrix(paramList);
sould also construct the object again while this
martix test2 = matrix(paramList); //is OK
quote:
Original post by sage2003
i assumed that once the default constructor was used to construct test doing this ( test = Point3d(1,1,1) ) would be tring to reconstruct the object test.
quote:
Original post by Miserable
[quote]Original post by sage2003
i assumed that once the default constructor was used to construct test doing this ( test = Point3d(1,1,1) ) would be tring to reconstruct the object test.
quote:
i say this because futher in the book on effecient programing
the auther stated that dealing with large class objects such as
a matrix and given an example of this class with the defined overloaded operators for addition subtraction etc and optimizations made to c++ that this
matrix MatrixAdd(paramList)
{
matrix result;
//do work
return result
}
would be rewritten to
void matrixAdd(matrix &result,paramList)
{
//directly compute into result
{
/////please remember this is just for example
quote:
and so doing this
Matrix test2; //default construct
test2 = test3 + test4;
would invoke your defined operator and the compiler would rewrite
matrix operator+(paramList);
to this
void operator+(test2,paramList);
because the first thing done to the object (test2) is to applied the constructor that has been applied to the local object.The author stated that test2 should not be allready
constructed and so this would construct the object test2 a second
time.
quote:
if that is so then the orginal post or this
matrix test2;
test2 = matrix(paramList);
sould also construct the object again while this
martix test2 = matrix(paramList); //is OK
quote:
Original post by Miserable
To the best of my knowledge, you cannot call a constructor on an already constructed object.
#include <iostream>
class Temp {
public:
Temp(int i) : _i(i) {
std::cout << "Temp()" << std::endl;
}
~Temp() {
std::cout << "~Temp()" << std::endl;
}
operator int() {
return _i;
}
private:
int _i;
};
int main() {
{
Temp t(1);
std::cout << t << std::endl;
new (&t) Temp(5);
std::cout << t << std::endl;
}
return 0;
}
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more