Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Michael Randolph

@Michael Randolph
About
Posts
8
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Problem with return value of private variable within class
    M Michael Randolph

    Thank you so much for your help. Looks like I have a bit of studying to do. I am not totally sure how this works but it does. Here is the fixed source in case someone needs to check it out.

    #include <iostream>

    using namespace std;

    class Point
    {
    public:
    Point(float f_x = 1.0, float f_y = 1.0, float f_z = 1.0);
    ~Point();

    void setXYZ(float X, float Y, float Z);
    void setX(float X);
    void setY(float Y);
    void setZ(float Z);
    
    // return by reference
    void getXYZ(float &X, float &Y, float &Z);
    float getX() const;
    float getY() const;
    float getZ() const;
    
    // overloading = operator to deal with pointers
    Point& operator =(Point const &p);
    

    private:
    float x, y, z;

    protected:

    };

    // define constructor with args
    Point::Point(float f_x, float f_y, float f_z)
    {
    cout << "We're in the constructor with arguments " << (int)this /*unique identifier*/ << endl;
    x = f_x;
    y = f_y;
    z = f_z;
    }

    // define destructor
    Point::~Point()
    {
    cout << "Destructing now!!! " << (int)this /*unique identifier*/ << endl;
    }

    // public function to return private value of variable x
    float Point::getX() const
    {
    return x;
    }

    // public function to return private value of variable y
    float Point::getY() const
    {
    return y;
    }

    // public function to return private value of variable z
    float Point::getZ() const
    {
    return z;
    }

    // public function to change value of private variable x
    void Point::setX(float X)
    {
    x = X;
    }

    // public function to change value of private variable y
    void Point::setY(float Y)
    {
    y = Y;
    }

    // public function to change value of private variable z
    void Point::setZ(float Z)
    {
    z = Z;
    }

    // public function to change value of all three private variables
    void Point::setXYZ(float X, float Y, float Z)
    {
    /* slower
    setX(X);
    setY(Y);
    setZ(Z);*/
    // faster
    x = X;
    y = Y;
    z = Z;

    }

    // public function to return values of x,y,z by reference
    void Point::getXYZ(float &X, float &Y, float &Z)
    {
    X = getX();
    Y = getY();
    Z = getZ();
    }

    // overloading = operator
    Point& Point::operator =(Point const &p)
    {
    setX(p.getX());
    setY(p.getY());
    setZ(p.getZ());
    // passing back value rather than address
    return *this;
    }

    // overloading operator << (output stream)
    ostream &operator <<(ostream &stream, Point &p)
    {
    stream << p.getX() << " " << p.getY() << " " << p.getZ();
    return stream;
    }

    // overloading operator >> (input

    C / C++ / MFC linux performance help question

  • Problem with return value of private variable within class
    M Michael Randolph

    ahh I see. That makes so much more sense! Thanks for your responses. My next question deals with inheritance. It appears that the = operator declaration is not being inherited from my class Point. I am getting this compiling error:

    g++ -o inheritance inheritance.cpp
    inheritance.cpp: In function ‘int main()’:
    inheritance.cpp:165: error: no match for ‘operator=’ in ‘vect3 = Vector::operator+(Vector&)(((Vector&)(& vect2)))’
    inheritance.cpp:135: note: candidates are: Vector& Vector::operator=(Vector&)

    here is my source:

    #include <iostream>

    using namespace std;

    class Point
    {
    public:
    Point(float f_x = 1.0, float f_y = 1.0, float f_z = 1.0);
    ~Point();

    // return by reference
    void getXYZ(float &X, float &Y, float &Z);
    float getX();
    float getY();
    float getZ();
    
    void setXYZ(float X, float Y, float Z);
    void setX(float X);
    void setY(float Y);
    void setZ(float Z);	
    
    // overloading = operator to deal with pointers
    Point operator = (Point &p);
    

    private:
    float x, y, z;

    protected:

    };

    // define constructor with args
    Point::Point(float f_x, float f_y, float f_z)
    {
    cout << "We're in the constructor with arguments " << (int)this /*unique identifier*/ << endl;
    x = f_x;
    y = f_y;
    z = f_z;
    }

    // define destructor
    Point::~Point()
    {
    cout << "Destructing now!!! " << (int)this /*unique identifier*/ << endl;
    }

    // public function to return private value of variable x
    float Point::getX()
    {
    return x;
    }

    // public function to return private value of variable y
    float Point::getY()
    {
    return y;
    }

    // public function to return private value of variable z
    float Point::getZ()
    {
    return z;
    }

    // public function to change value of private variable x
    void Point::setX(float X)
    {
    x = X;
    }

    // public function to change value of private variable y
    void Point::setY(float Y)
    {
    y = Y;
    }

    // public function to change value of private variable z
    void Point::setZ(float Z)
    {
    z = Z;
    }

    // public function to change value of all three private variables
    void Point::setXYZ(float X, float Y, float Z)
    {
    /* slower
    setX(X);
    setY(Y);
    setZ(Z);*/
    // faster
    x = X;
    y = Y;
    z = Z;

    }

    // public function to return values of x,y,z by reference
    void Point::getXYZ(float &X, float &Y, float &Z)
    {
    X = getX();
    Y = getY();
    Z = getZ();
    }

    // overloading operator << (output stream)
    ostream &operator <<(ostream &stream, Point &p)
    {
    stream << p.getX() <

    C / C++ / MFC linux performance help question

  • Problem with return value of private variable within class
    M Michael Randolph

    I thought once you instantiate the object it sets the variables that I have for parameters in the function? Where am I forgetting something? This should work as far as I can see.

    C / C++ / MFC linux performance help question

  • Problem with return value of private variable within class
    M Michael Randolph

    When I instantiate the object with this:

    // create instance of class
    Point myLocation(23, 54, 32);

    That should assign values 23, 54, 32 to x, y, and z, respectively.

    C / C++ / MFC linux performance help question

  • Problem with return value of private variable within class
    M Michael Randolph

    I am compiling with g++ 4.2.4 on Ubuntu Hardy. I am trying to creating a public function to return a value of a private variable within the class. The output I am getting is not correct. What did I miss here?

    #include <iostream>

    using namespace std;

    class Point
    {
    public:
    // constructors
    Point(float f_x = 1.0, float f_y = 1.0, float f_z = 1.0);

    // destructors (Only necessary for new dynamic memory created)
    ~Point();
    
    float getX();
    

    private:
    float x, y, z;

    protected:

    };

    // define constructor with args
    Point::Point(float f_x, float f_y, float f_z)
    {
    cout << "We're in the constructor with arguments " << (int)this /*unique identifier*/ << endl;
    }

    // define destructor
    Point::~Point()
    {
    cout << "Destructing now!!! " << (int)this /*unique identifier*/ << endl;
    }

    // public function to return private value of variable x
    float Point::getX()
    {
    return x;
    }

    int main()
    {
    // create instance of class
    Point myLocation(23, 54, 32);

    // create another instance of class
    //Point anotherLocation;
    
    // calling constructor with args
    //Point thirdLocation(23, 14, 52);
    
    // return value of x
    cout << myLocation.getX() << endl;
    
    return 0;
    

    }

    C / C++ / MFC linux performance help question

  • Linux junkies and programmers
    M Michael Randolph

    I've started a new website and I am looking for members interested in programming and linux. We are needing people who have the desire to learn linux on a higher level. Subdomains, FTP accounts, and web space for members will be offered sparingly to those seriously interested. datdirt.com

    C / C++ / MFC com linux

  • File stream filtering and formatting
    M Michael Randolph

    Yes if you check out this link there is more info on what I'm trying to do..... http://www.codeguru.com/forum/showthread.php?t=464131

    C / C++ / MFC c++ database linux tools regex

  • File stream filtering and formatting
    M Michael Randolph

    I have a project here at my work due Monday and it involves 23,000+ records to be manually typed into a database requiring the fields LEN:, DN:, and the NCOS: on the same line. I just know that there is an easier way of doing it. I have been working with the sed utility in Linux to help me but now I would like to know how to write an Win32 executable that can ask for the file name and filter these values for me and insert them into a text file. I have a fair amount of C++ programming experience but I do not know how to using file streams. Any help would be greatly appreciated by myself and my coworkers. A sample of a record I have is:

    MADN SPECIFIED. LEN OUTPUT IS FOR PRIMARY.

    LEN: HOST 02 0 02 11
    TYPE: MULTIPLE APPEARANCE DIRECTORY NUMBER
    SNPA: 315
    DIRECTORY NUMBER: 6344010 (NON-UNIQUE)
    LINE CLASS CODE: IBN
    CUSTGRP: KAFB SUBGRP: 0 NCOS: 52

    Here is a link to a thread where I was using sed: http://www.linuxquestions.org/questions/linux-software-2/using-sed-to-extract-a-pattern-plus-a-number-of-positions-after-679435/

    C / C++ / MFC c++ database linux tools regex
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups