how to pass a name

Started by
2 comments, last by Qw3r7yU10p! 19 years, 3 months ago
ok i have a problem here. I want to be able to to create a function for a class the in the constructor pass and name for the class i am create. to try to show you want i me hey is what i what to be able to do, something like this: i have a class cam point and the defualt count i give x and y but i also what to pass a name and in the function give it the name, some like this: construtor: Point::Point( int x, int y, string(or whatever) name) { Point *name(the passed value in the parameter) = new Point( x, y, "" ); } and that function happens when i call Point( 8, 8, "pointa" ); is it possible using the construtor? is it possible any other what?
Advertisement
I seriously doubt that you can use a constructor.

None the less, to do what you've asked, it's like this:
#define createPoint(x,y,name)   Point* name = new Point(x,y,"");
I don't think you've thought this through.

You wouldn't be able to refer to the variable in your code because you wouldn't know what it was going to be called. The point of variables is they vary!

Why would you need to do it?

What would the code further on in the function look like? It doesn't make any sense.
Or if I've misunderstood you
//Point.h#include <string>class Point {    std::string m_name;    int m_x,        m_y,        m_z;public:    Point(int x, int y, const std::string& name)        : m_x(x), m_y(y), m_name(name) {    }    const std::string& Name() const {        return m_name;    }}


Usage:
#include <iostream>#include "Point.h"int main() {    Point point(2, 5, "pointa");    std::cout << point.Name() << std::endl;    return 0;}

This topic is closed to new replies.

Advertisement