Notices
Results 1 to 2 of 2

Thread: Why are my dynamic variables (in the class) unidentified, even after creating and initializing it in the constructor of the class?

  1. #1 Why are my dynamic variables (in the class) unidentified, even after creating and initializing it in the constructor of the class? 
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    908
    here's the class:
    Code:
    class taxi{
    private:
        int count;
        struct standard{
            int age;
            char model;
        };
    public:
        double getAvgAge(void){
            int total_age=0;
            for(int i=0;i<count;i++){
                total_age+=standard_obj[i].age;
            }
            return (double(total_age)/count);
        }
        taxi (void){
            count=3;
            standard *standard_obj=new standard[count];
            for(int i=0;i<count;i++){
                standard_obj[i].age=0;
            standard_obj[i].model='x';
            }
        }
        ~taxi (void){
            delete[] standard_obj;
        }
    };
    1. 'standard_obj':undeclared identifier.
    2. left of '.age' must have a class/struct/union.
    3. identifier "standard_obj" is undefined.
    4. cannot delete objects that are not pointers.
    im guessing theres a problem with the initializing of the structure-type variable using a pointer. i cant spot any mistakes, but im sure something must be wrong somewhere.
    any help is appreciated!


    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    908
    Okay, i found the problem by myself after going through line by line.


    I declared AND defined the dynamic variable in the constructor, by shifting the declaration out of the constructor, my problem is solved.


    sorry for the error its my careless mistake!

    thread closed.
    (i dont know how to close the thread anyway haha!)


    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

Similar Threads

  1. Calling Base Class Constructors from Derived Class c++
    By muhammadjaziem in forum Computer Science
    Replies: 1
    Last Post: March 31st, 2013, 04:39 AM
  2. Help me decide what class I should take?
    By elegance in forum Computer Science
    Replies: 2
    Last Post: November 7th, 2010, 07:51 AM
  3. Science class...What do u think?
    By ceire in forum General Discussion
    Replies: 7
    Last Post: July 19th, 2009, 12:59 PM
  4. taxonomic class
    By godspanther in forum Biology
    Replies: 3
    Last Post: May 18th, 2009, 12:52 AM
  5. class system
    By Kenny Klassen in forum Biology
    Replies: 23
    Last Post: April 11th, 2008, 07:10 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •