Thread: Need help figuring out compile error.

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    1

    Need help figuring out compile error.

    I'm getting a compile error complaining that it 'can't call a member function of 'a' without an object.'

    Here's the code I believe it's related to...
    In header file a.h
    class a{
    private:
    stuff.....
    public:
    a * functionx(args....);
    }


    In source code a.cpp
    I include header file
    then try to call

    a *const b = a::funtionx(args.....)

    Any idea why the compiler is complaining about the call in a.cpp?
    Any help is appreciated. Thanks.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    because you are not calling it through an object. To call a nonstatic member function you need an object and you dont have one.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well that didnt tell you much more than the error so heres one way of fixing it...

    a Mya;
    a*const b=Mya.functionx(ARGS);
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    3
    Thanks Stoned! That cleared it up and was a great help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM