Results 1 to 5 of 5

Thread: C++ no member function declared in class

  1. #1
    Join Date
    Jun 2008
    Location
    Kitchener, Ontario
    Beans
    8
    Distro
    Ubuntu 9.10 Karmic Koala

    Question C++ no member function declared in class

    I am working in Code::Blocks on a C++ program and trying to keep my functions organized in seperate class and header files.
    Could someone let me know what I'm doing wrong.
    I get this message when I try to test/compile:
    ~/Programs/Disc Master/media.cpp|14|error: no ‘void media::disctype()’ member function declared in class ‘media’|
    the same error occurs for ripmusic and dvdmanip

    Currently the compiler for the project is on GCC, I checked to see if G++ is installed and it is, but it's not selectable in Code::Blocks.

    As you can see it's pretty simple code just setting up functions.

    cpp

    Code:
    #include "media.h"
    
    //using namespace std;
    media::media()
    {
        //ctor
    }
    
    media::~media()
    {
        //dtor
    }
    
    void media::disctype()
    {
        do
            detectdisc= system(cdde -b)
        while detectdisc != ""
    
        if (detectdisc == "An audio cd was inserted.")
        {
            ripmusic();
        }
        else if (detectdisc == "A dvd was inserted.")
        {
            dvdmanip();
        }
    }
    
    void media::ripmusic()
    {
        musicrip.hidden=false
    }
    
    void media::dvdmanip()
    {
        //musicrip.hidden=false
    }
    header

    Code:
    #ifndef MUSIC_H
    #define MUSIC_H
    using namespace std;
    
    class media
    {
        public:
            media();
            virtual ~media();
    
        protected:
            string detectdisc;
        private:
    
    };
    
    class disctype: public media
    {
        public:
            disctype();
    };
    
    class ripmusic: public media
    {
        public:
            ripmusic();
    };
    
    class dvdmanip: public media
    {
        public:
            dvdmanip();
    };
    
    #endif // MUSIC_H

  2. #2
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: C++ no member function declared in class

    Disctype is a class.
    Maybe you mean:

    Code:
    disctype::disctype() {...}
    And a constructor cannot have a return type, in this case void.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  3. #3
    Join Date
    Jul 2009
    Beans
    109
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: C++ no member function declared in class

    If i'm not mistaken you are trying to define member functions which according to the class do not exist.
    therfore you have to change the class header in order to accomodate the funtions.

    Code:
    class media
    {
        public:
            media();
            virtual ~media();
            void disctype(void);
            void ripmusic(void);
            void dvdmanip(void);
    
        protected:
            std::string detectdisc;
        private:
    
    };
    But there are more problems ahead. Like u should probably not make namespace std available in a header. The standard template library is put into a namespace for a reason. Now every file that includes your media header has the STL available, i think this is bad coding style you also forgot to include #include <string>.

    well the adaptation of the class should fix the error you created by defining the funtions in the .cpp file but did not declare in the class declaration , but there is more ahead.

    cheers,

    Maarten
    Windows DOS not compute...

  4. #4
    Join Date
    Jun 2008
    Location
    Kitchener, Ontario
    Beans
    8
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: C++ no member function declared in class

    Unfortunately when I change 'void media::*()' to *::*()' (sub * for disctype, ripmusic, and dvdmanip) I get errors saying cdde and b are not declared in the scope, I added some ;'s and brackets where I was missing them so the error count dropped.

    Pre-post edit:

    The issue with the cdde and b was they weren't inside quotes. Trying to learn c++ coming from a vb(6,2008,.NET) background so used to autocomplete taking care of the little nuances like these.

  5. #5
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,240
    Distro
    Kubuntu

    Re: C++ no member function declared in class

    Quote Originally Posted by sony_gamer View Post
    ... so used to autocomplete taking care of the little nuances like these.
    Yes, I hear this all the time. It's the editor's (or IDE's) fault, not the programmer's.

    I agree with what Hetepeperfan stated concerning the (mis)use of "using namespace" declarations within header files; they should be avoided.

    Also, you might want to consider changing your class names to begin with an uppercase letter, so as not to confuse a class name with a method (function) name. When all objects, functions, and variables (whether local or class-scoped) have the same style of lettering, it is difficult to discern one from the other in an efficient manner.

Tags for this Thread

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
  •