Thread: class scope

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    39

    class scope

    i want to get the number of rows from my class Matrix and rows are dynamically created.
    what is the method so than i can get the number of rows.should i use dot operator?
    once a kohatian,always a kohatian!

  2. #2
    Unregistered
    Guest
    It's better to make all data in a class private and access it with functions...

    myclass c;
    int data = c.getdata();

    class myclass
    {
    public:
    myclass() { data = 5; }
    int getdata() { return data; }

    private:
    int data;
    };

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Have a data member in your class that gets set to the number of rows whenever the matrix gets allocated. Then simply have your method return the value of that data member. Initialize it to 0 in the constructor(s).
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  2. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  3. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  4. Class scope variables
    By filler_bunny in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2003, 02:14 AM