no match for call to vector of inner class objects












1















I have a class and i tried to construct this class with Point2D object vector.



        class Polygon{//Polygon.h
public:
//-----------POINT CLASS----------
class Point2D{
public:
Point2D(double param_x = 0, double param_y = 0);
double getX() const;
double getY() const;
void setX(double setX);
void setY(double setY);
private:
double x;
double y;
};
Polygon(vector<Polygon::Point2D>& pointVec);
private:
int capacity;
Point2D* points;//For dynamic array
}

Polygon::Polygon(vector<Polygon::Point2D>& pointVec){//Vector constructor from polygon.cpp
capacity = pointVec.size();
points = new Polygon::Point2D[capacity];
for(int i = 0; i < capacity; i++)
points[i] = pointVec[i];
}//Vector of 2D points


But when i tried to construct an object of Polygon object with vector of Point2D objects its give me an error like



error: no match for call to '(Polygon) (std::vector<Polygon::Point2D>&)'
return newPoly(newObj);


up here newPoly is Polygon object and newObj is vector of Point2D objects.



This here where code give error.



const Polygon Polygon::operator +(const Polygon& otherPoly) const{
vector<Polygon::Point2D> newObj;
Polygon newPoly;
if(capacity > otherPoly.getCapacity()){
for(int i = 0; i < otherPoly.getCapacity(); i++){
Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = otherPoly.getCapacity() + 1; j < capacity; j++){
Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity < otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = capacity + 1; j < otherPoly.getCapacity(); j++){
Polygon::Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity == otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}

return newPoly(newObj);

}
}









share|improve this question




















  • 1





    Side note: Don't use raw pointers. In your case you could use a vector. See isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.

    – Werner Henze
    Nov 22 '18 at 9:08






  • 1





    Please show the code that triggers the error.

    – Werner Henze
    Nov 22 '18 at 9:09
















1















I have a class and i tried to construct this class with Point2D object vector.



        class Polygon{//Polygon.h
public:
//-----------POINT CLASS----------
class Point2D{
public:
Point2D(double param_x = 0, double param_y = 0);
double getX() const;
double getY() const;
void setX(double setX);
void setY(double setY);
private:
double x;
double y;
};
Polygon(vector<Polygon::Point2D>& pointVec);
private:
int capacity;
Point2D* points;//For dynamic array
}

Polygon::Polygon(vector<Polygon::Point2D>& pointVec){//Vector constructor from polygon.cpp
capacity = pointVec.size();
points = new Polygon::Point2D[capacity];
for(int i = 0; i < capacity; i++)
points[i] = pointVec[i];
}//Vector of 2D points


But when i tried to construct an object of Polygon object with vector of Point2D objects its give me an error like



error: no match for call to '(Polygon) (std::vector<Polygon::Point2D>&)'
return newPoly(newObj);


up here newPoly is Polygon object and newObj is vector of Point2D objects.



This here where code give error.



const Polygon Polygon::operator +(const Polygon& otherPoly) const{
vector<Polygon::Point2D> newObj;
Polygon newPoly;
if(capacity > otherPoly.getCapacity()){
for(int i = 0; i < otherPoly.getCapacity(); i++){
Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = otherPoly.getCapacity() + 1; j < capacity; j++){
Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity < otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = capacity + 1; j < otherPoly.getCapacity(); j++){
Polygon::Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity == otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}

return newPoly(newObj);

}
}









share|improve this question




















  • 1





    Side note: Don't use raw pointers. In your case you could use a vector. See isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.

    – Werner Henze
    Nov 22 '18 at 9:08






  • 1





    Please show the code that triggers the error.

    – Werner Henze
    Nov 22 '18 at 9:09














1












1








1








I have a class and i tried to construct this class with Point2D object vector.



        class Polygon{//Polygon.h
public:
//-----------POINT CLASS----------
class Point2D{
public:
Point2D(double param_x = 0, double param_y = 0);
double getX() const;
double getY() const;
void setX(double setX);
void setY(double setY);
private:
double x;
double y;
};
Polygon(vector<Polygon::Point2D>& pointVec);
private:
int capacity;
Point2D* points;//For dynamic array
}

Polygon::Polygon(vector<Polygon::Point2D>& pointVec){//Vector constructor from polygon.cpp
capacity = pointVec.size();
points = new Polygon::Point2D[capacity];
for(int i = 0; i < capacity; i++)
points[i] = pointVec[i];
}//Vector of 2D points


But when i tried to construct an object of Polygon object with vector of Point2D objects its give me an error like



error: no match for call to '(Polygon) (std::vector<Polygon::Point2D>&)'
return newPoly(newObj);


up here newPoly is Polygon object and newObj is vector of Point2D objects.



This here where code give error.



const Polygon Polygon::operator +(const Polygon& otherPoly) const{
vector<Polygon::Point2D> newObj;
Polygon newPoly;
if(capacity > otherPoly.getCapacity()){
for(int i = 0; i < otherPoly.getCapacity(); i++){
Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = otherPoly.getCapacity() + 1; j < capacity; j++){
Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity < otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = capacity + 1; j < otherPoly.getCapacity(); j++){
Polygon::Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity == otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}

return newPoly(newObj);

}
}









share|improve this question
















I have a class and i tried to construct this class with Point2D object vector.



        class Polygon{//Polygon.h
public:
//-----------POINT CLASS----------
class Point2D{
public:
Point2D(double param_x = 0, double param_y = 0);
double getX() const;
double getY() const;
void setX(double setX);
void setY(double setY);
private:
double x;
double y;
};
Polygon(vector<Polygon::Point2D>& pointVec);
private:
int capacity;
Point2D* points;//For dynamic array
}

Polygon::Polygon(vector<Polygon::Point2D>& pointVec){//Vector constructor from polygon.cpp
capacity = pointVec.size();
points = new Polygon::Point2D[capacity];
for(int i = 0; i < capacity; i++)
points[i] = pointVec[i];
}//Vector of 2D points


But when i tried to construct an object of Polygon object with vector of Point2D objects its give me an error like



error: no match for call to '(Polygon) (std::vector<Polygon::Point2D>&)'
return newPoly(newObj);


up here newPoly is Polygon object and newObj is vector of Point2D objects.



This here where code give error.



const Polygon Polygon::operator +(const Polygon& otherPoly) const{
vector<Polygon::Point2D> newObj;
Polygon newPoly;
if(capacity > otherPoly.getCapacity()){
for(int i = 0; i < otherPoly.getCapacity(); i++){
Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = otherPoly.getCapacity() + 1; j < capacity; j++){
Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity < otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}
for(int j = capacity + 1; j < otherPoly.getCapacity(); j++){
Polygon::Point2D obj_2(points[j].getX() + otherPoly[j].getX(), points[j].getY() + otherPoly[j].getY());
newObj.push_back(obj_2);
}

return newPoly(newObj);

} else if(capacity == otherPoly.getCapacity()){
for(int i = 0; i < capacity; i++){
Polygon::Point2D obj(points[i].getX() + otherPoly[i].getX(), points[i].getY() + otherPoly[i].getY());
newObj.push_back(obj);
}

return newPoly(newObj);

}
}






c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 9:14







Furkan Kalabalık

















asked Nov 22 '18 at 8:53









Furkan KalabalıkFurkan Kalabalık

813




813








  • 1





    Side note: Don't use raw pointers. In your case you could use a vector. See isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.

    – Werner Henze
    Nov 22 '18 at 9:08






  • 1





    Please show the code that triggers the error.

    – Werner Henze
    Nov 22 '18 at 9:09














  • 1





    Side note: Don't use raw pointers. In your case you could use a vector. See isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.

    – Werner Henze
    Nov 22 '18 at 9:08






  • 1





    Please show the code that triggers the error.

    – Werner Henze
    Nov 22 '18 at 9:09








1




1





Side note: Don't use raw pointers. In your case you could use a vector. See isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.

– Werner Henze
Nov 22 '18 at 9:08





Side note: Don't use raw pointers. In your case you could use a vector. See isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.

– Werner Henze
Nov 22 '18 at 9:08




1




1





Please show the code that triggers the error.

– Werner Henze
Nov 22 '18 at 9:09





Please show the code that triggers the error.

– Werner Henze
Nov 22 '18 at 9:09












2 Answers
2






active

oldest

votes


















1














You are calling return newPoly(newObj). This is not calling the Polygon constructor that is taking a vector. This tries to find an operator(std::vector<Point2D>) inside Polygon. If you want to call the constructor you need to return Polygon(newObj); or return Polygon{newObj};.






share|improve this answer
























  • This one is work. Thank you.

    – Furkan Kalabalık
    Nov 22 '18 at 9:16



















1














You have not declared the Polygon(vector<Polygon::Point2D>& pointVec) constructor within the class. Try to add



Polygon(vector<Polygon::Point2D>& pointVec);


Into the Polygon class declaration






share|improve this answer
























  • I've done what you said and it's still giving same error

    – Furkan Kalabalık
    Nov 22 '18 at 9:02











  • In the question as currently written that ctor is declared in the class.

    – Werner Henze
    Nov 22 '18 at 9:06











  • Actually I didn't declare a vector inside class. I just want to pass parameter to constructor but it doesn't recognize.

    – Furkan Kalabalık
    Nov 22 '18 at 9:11











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427063%2fno-match-for-call-to-vector-of-inner-class-objects%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You are calling return newPoly(newObj). This is not calling the Polygon constructor that is taking a vector. This tries to find an operator(std::vector<Point2D>) inside Polygon. If you want to call the constructor you need to return Polygon(newObj); or return Polygon{newObj};.






share|improve this answer
























  • This one is work. Thank you.

    – Furkan Kalabalık
    Nov 22 '18 at 9:16
















1














You are calling return newPoly(newObj). This is not calling the Polygon constructor that is taking a vector. This tries to find an operator(std::vector<Point2D>) inside Polygon. If you want to call the constructor you need to return Polygon(newObj); or return Polygon{newObj};.






share|improve this answer
























  • This one is work. Thank you.

    – Furkan Kalabalık
    Nov 22 '18 at 9:16














1












1








1







You are calling return newPoly(newObj). This is not calling the Polygon constructor that is taking a vector. This tries to find an operator(std::vector<Point2D>) inside Polygon. If you want to call the constructor you need to return Polygon(newObj); or return Polygon{newObj};.






share|improve this answer













You are calling return newPoly(newObj). This is not calling the Polygon constructor that is taking a vector. This tries to find an operator(std::vector<Point2D>) inside Polygon. If you want to call the constructor you need to return Polygon(newObj); or return Polygon{newObj};.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 9:12









Werner HenzeWerner Henze

10.7k72854




10.7k72854













  • This one is work. Thank you.

    – Furkan Kalabalık
    Nov 22 '18 at 9:16



















  • This one is work. Thank you.

    – Furkan Kalabalık
    Nov 22 '18 at 9:16

















This one is work. Thank you.

– Furkan Kalabalık
Nov 22 '18 at 9:16





This one is work. Thank you.

– Furkan Kalabalık
Nov 22 '18 at 9:16













1














You have not declared the Polygon(vector<Polygon::Point2D>& pointVec) constructor within the class. Try to add



Polygon(vector<Polygon::Point2D>& pointVec);


Into the Polygon class declaration






share|improve this answer
























  • I've done what you said and it's still giving same error

    – Furkan Kalabalık
    Nov 22 '18 at 9:02











  • In the question as currently written that ctor is declared in the class.

    – Werner Henze
    Nov 22 '18 at 9:06











  • Actually I didn't declare a vector inside class. I just want to pass parameter to constructor but it doesn't recognize.

    – Furkan Kalabalık
    Nov 22 '18 at 9:11
















1














You have not declared the Polygon(vector<Polygon::Point2D>& pointVec) constructor within the class. Try to add



Polygon(vector<Polygon::Point2D>& pointVec);


Into the Polygon class declaration






share|improve this answer
























  • I've done what you said and it's still giving same error

    – Furkan Kalabalık
    Nov 22 '18 at 9:02











  • In the question as currently written that ctor is declared in the class.

    – Werner Henze
    Nov 22 '18 at 9:06











  • Actually I didn't declare a vector inside class. I just want to pass parameter to constructor but it doesn't recognize.

    – Furkan Kalabalık
    Nov 22 '18 at 9:11














1












1








1







You have not declared the Polygon(vector<Polygon::Point2D>& pointVec) constructor within the class. Try to add



Polygon(vector<Polygon::Point2D>& pointVec);


Into the Polygon class declaration






share|improve this answer













You have not declared the Polygon(vector<Polygon::Point2D>& pointVec) constructor within the class. Try to add



Polygon(vector<Polygon::Point2D>& pointVec);


Into the Polygon class declaration







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 8:57









jlanikjlanik

38419




38419













  • I've done what you said and it's still giving same error

    – Furkan Kalabalık
    Nov 22 '18 at 9:02











  • In the question as currently written that ctor is declared in the class.

    – Werner Henze
    Nov 22 '18 at 9:06











  • Actually I didn't declare a vector inside class. I just want to pass parameter to constructor but it doesn't recognize.

    – Furkan Kalabalık
    Nov 22 '18 at 9:11



















  • I've done what you said and it's still giving same error

    – Furkan Kalabalık
    Nov 22 '18 at 9:02











  • In the question as currently written that ctor is declared in the class.

    – Werner Henze
    Nov 22 '18 at 9:06











  • Actually I didn't declare a vector inside class. I just want to pass parameter to constructor but it doesn't recognize.

    – Furkan Kalabalık
    Nov 22 '18 at 9:11

















I've done what you said and it's still giving same error

– Furkan Kalabalık
Nov 22 '18 at 9:02





I've done what you said and it's still giving same error

– Furkan Kalabalık
Nov 22 '18 at 9:02













In the question as currently written that ctor is declared in the class.

– Werner Henze
Nov 22 '18 at 9:06





In the question as currently written that ctor is declared in the class.

– Werner Henze
Nov 22 '18 at 9:06













Actually I didn't declare a vector inside class. I just want to pass parameter to constructor but it doesn't recognize.

– Furkan Kalabalık
Nov 22 '18 at 9:11





Actually I didn't declare a vector inside class. I just want to pass parameter to constructor but it doesn't recognize.

– Furkan Kalabalık
Nov 22 '18 at 9:11


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427063%2fno-match-for-call-to-vector-of-inner-class-objects%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy