-4

I'm having difficulty with what I think is classes (Code below), I've read up on so much about classes yet during my tutorial lessons I find certain aspects difficult to grasp.

Basically the idea is to output a shape on the screen using an object orientated method. I cannot for the life of my understand what the following code means. Both vertex and Rhombus are classes but what is going on after that.

I just really need to know where I can find the information about these following lines, how I manipulate them to call them in main etc. if anyone can even point me in the right direction using key words of what types of coding the lines use other than classes that'd be amazing. Thanks in advance, never posted before so, sorry if this is the wrong forum or something.

Rhombus::Rhombus(Vertex point, int radius) : Shape(point)

shapes.push_back(new Rhombus(Vertex(20, 20), 8));

edit - Thanks, seems I need to read up alot on constructors.

HLGgaming
  • 3
  • 2
  • 3
    Welcome to stackoverflow.com. You might want to start with reading [the Stack Overflow question checklist](http://meta.stackoverflow.com/questions/156810/stack-overflow-question-checklist). You might also want to learn how to create a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Some programmer dude Jul 21 '14 at 06:28
  • Oh, and of course you should also take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). – Some programmer dude Jul 21 '14 at 06:32
  • As for your question, you might want to elaborate on what you want to accomplish, and what you have tried so far (preferably by showing *some relevant* code). If you have errors you should edit your question to include all of them, unedited. If you haven't tried anything special, please try to explain more clearly what your problem is, what is it you don't understand about those two lines of code? Have you read about [`std::vector`](http://en.cppreference.com/w/cpp/container/vector) (which I assume that `shapes` is)? – Some programmer dude Jul 21 '14 at 06:35
  • If you've read up on so much about classes and you're still confused about this, at the risk of sounding harsh, you are reading it wrong or your material is wrong. Also, a quick read on `.push_back` tells you it's pretty much putting something inside a container like a list or vector. – WGS Jul 21 '14 at 06:36
  • And finally, you might want to check out [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), especially the tutorials and beginner books. – Some programmer dude Jul 21 '14 at 06:36

2 Answers2

0

It would be helpful to show more context here.

The first line appears to be the definition of a constructor for a class named Rhombus. Rhombus either has a base class named Shape or a field named Shape. The constructor takes two arguments, a Vertex named point, and an int named radius. It initializes Shape (either a base class or a field) with point in the member initialization list, and presumably does something with radius in the constructor's body.

The second line dynamically allocates a Rhombus object, passing a temporary Vertex and an integer literal as the arguments to its constructor. It appears to then append it to an std::vector (or something with a similar interface) named shapes.

user3553031
  • 5,990
  • 1
  • 20
  • 40
0

The first line defines a constructor for the Rhombus class. It takes two parameters: a Vertex object called shape and an int called radius. All this constructor does is call the constructor of its base class (Shape), passing it the point variable; the radius is ignored. (But you haven't shown the constructor's body — the part in { } — so that might do additional things beyond what I've described here.)

The second line constructs a Rhombus object on the heap (using new) and stores a its address into a container called shapes, which is presumably something like a std::vector<Shape *> or std::list<Shape *>. The Rhombus is constructed by first constructing a Vector with the parameters 20 and 20, then passing that vector and the number 8 as the point and radius parameters, respectively, of the Rhombus constructor.

Wyzard
  • 33,849
  • 3
  • 67
  • 87