class scope

This is a discussion on class scope within the C++ Programming forums, part of the General Programming Boards category; i want to get the number of rows from my class Matrix and rows are dynamically created. what is the ...

  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,793
    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
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21