0

Ok I edit my code, what I want to do is simple I have a big shape with corrdinates(x,y). what I want to do is resize my primitive shape, store it inside new figure inside a class called "new" and move this new shape to the cordinates (x,y) I want.

// Example program
#include <iostream>
#include <string>

// Base class Shape

class Shape 
 {
 public:

Shape(int inwidth, int inheight): width(inwidth), height(inheight){
}
void ResizeW(int w)
{
 width = w;
}
void ResizeH(int h)
{
 height = h;
}
 void moveF(int x_delta, int y_delta) 
{
x1 = x_delta;
y1 = y_delta;
x2 = x_delta;
y2 = y_delta;
}

 protected:

int x1=0, y1=0, x2=5, y2=6;
int width;
int height;
 };

 // Primitive Shapes

 class Ps2: public Shape
 {
 public:

Ps2 (int width, int height): Shape(width, height){
 }
int getArea()
{
    return (width * height);
}
 };

 // Derived Shapes

class New: public Ps2 
{

 int x1_relativ, y1_relativ, x2_relativ, y2_relativ;
 public:
 int area;
 New(): Ps2(8, 4), area(getArea()){ }
 };



 int main(void)
 {
 New kit;
 moveF.kit (4, 3, 5, 7);
 std::cout << "Total area: " << kit.getArea();
 std::cout << "Cordinates are: " << kit.moveF();

 return 0;
 }

Now I have four errors: In function 'int main()': 66:6: error: 'moveF' was not declared in this scope 68:51: error: no matching function for call to 'New::moveF()' 68:51: note: candidate is: 21:11: note: void Shape::moveF(int, int) 21:11: note: candidate expects 2 arguments, 0 provided. Also I don't think i'm able to use "move.f" I created any help?

FL93
  • 29
  • 5
  • Your question is quite unclear, could you please detail what you need ? – shrike Jun 13 '16 at 21:44
  • @shrike I did a sketch. it can help – FL93 Jun 13 '16 at 21:51
  • Perhaps you want to create a `Shape` class, and then derive classes (like `Square` and `Ell`) from it. Is that what you mean? – Beta Jun 13 '16 at 22:56
  • @Beta sort of! but let's say that the classes I want to derive are shapes composed by geometric transformations of Square and Ell and has to placed inside my Shape class, what should I do? – FL93 Jun 13 '16 at 23:01
  • Perhaps you got a new username - as this is on the same theme http://stackoverflow.com/questions/37599215/inheritance-classes/37818554#comment63101528_37818554 – Ed Heal Jun 14 '16 at 17:55
  • I don't know what you mean by *"placed inside my Shape class"*. Do you mean composition? Perhaps you should attempt some simpler exercises before this one. – Beta Jun 14 '16 at 22:32
  • @Beta I hope I gave a better Idea. – FL93 Jun 14 '16 at 22:44
  • @EdHeal I'm the same user – FL93 Jun 14 '16 at 22:45

1 Answers1

0

Well, the compiler tells you exactly what the problem is:

moveF.kit (4, 3, 5, 7);

is no valid code. Did you mean kit.moveF? Also, why four parameters? moveF has two.

std::cout << "Cordinates are: " << kit.moveF();

has two errors, first, moveF requires two parameters which you don't provide, second, kit.moveF is a void and therefore will not produce anything that std::cout can display.

Also, your attributes x1, x2, y1, y2 can't be accessed from outside. This doesn't seem to be intended. A derived class could access them, but there is none that does right now.

Furthermore, New is a horrible name for a class. Confused me at first to see New kit;. New is obviously not reserved, but it feels reserved, if you know what I mean.

My advice is that you read a tutorial regarding classes and methods. It seems that your understanding how methods work is flawed.

Aziuth
  • 3,652
  • 3
  • 18
  • 36
  • I fixed it but now I get In function 'int main()': 68:47: error: no matching function for call to 'New::moveF()' 68:47: note: candidate is: 21:7: note: void Shape::moveF(int, int) 21:7: note: candidate expects 2 arguments, 0 provided @Aziuth – FL93 Jun 16 '16 at 16:26
  • Again, just as your compiler tells you: You call moveF without parameters but it requires two. You need to give some values for x_delta and y_delta. You need to call it like kit.moveF(5,3); But let's do the right approach, let's begin with you telling us what moveF is supposed to do. And what the class itself is supposed to do. Is moveF meant to translate the Shape? If so, why not x1 += x_delta? And why is x1 not used anymore? – Aziuth Jun 17 '16 at 11:49
  • @FL93 Maybe to give you something more solid, what you probably want in that line is to write std::cout << "Coordinates are: " << kit.getCoordinatesAsString(); with the method std::string getCoordinatesAsString(){ std::string ret = std::to_string(x1) + " " + std::to_string(x2) + " " + std::to_string(x3) + " " + std::to_string(x4); return ret; }. Since you tried to use moveF to accomplish that, again, I repeat, my advice is that you read a basic tutorial on how things work. – Aziuth Jun 17 '16 at 16:41
  • I was trying to do a translation, can I please have my code edited to understand it better? – FL93 Jun 20 '16 at 18:34
  • Before we do that, we'd need to begin with you specifying what the code is supposed to do. Also, you want to write your code on your own, you won't learn anything by copying code. What exactly do you not understand? What do you think your methods do? Describe them. And again, I cannot stress enough, you need basic tutorials! – Aziuth Jun 21 '16 at 08:26
  • I'm not trying to copy the code I just want to be able to set random coordinates by using the function "move", that supposing we are starting from (0,0) (0,0), it should display the value I set in int main – FL93 Jun 21 '16 at 08:58
  • Your method does neither. It is declared as void moveF(int x_delta, int y_delta). This means that it has two parameters, int x_delta and int y_delta. However, you call it with four or no parameters for some reason, which of course does not work. Also, it's return type is void, therefore it can't display any value. If you have troubles understanding that, again, read basic tutorials. – Aziuth Jun 21 '16 at 09:21