error : non static member reference must to be relative to specific object

This is a discussion on error : non static member reference must to be relative to specific object within the C++ Programming forums, part of the General Programming Boards category; Hi, i have problem with the call of my function i have function "newpos" defined as public in class2 in ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    57

    error : non static member reference must to be relative to specific object

    Hi,
    i have problem with the call of my function

    i have function "newpos" defined as public in class2

    in class1 i hav another function "add" i want to call "newpos"
    i make like that
    Code:
    void  class1::add()
    {
    class2::newpos
    }
    it make to me error
    Code:
    non static member reference must to be relative to specific object

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    It says that newpos is a member data of class 2. Classes are templates. In order to use it, you must create an instance.
    (It wouldn't make sense if you could actually change the throttle, in say, an engine template, would it?)
    You'd have to create an instance of class 2 and then modify its data.
    It would be a good idea to check class tutorials (they are available on the site).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Or perhaps you actually intend to make newpos a static method?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static reference member
    By Tux0r in forum C++ Programming
    Replies: 14
    Last Post: 07-17-2009, 10:21 AM
  2. Sizeof static member object?
    By jw232 in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 11:36 AM
  3. Replies: 7
    Last Post: 03-09-2006, 09:47 AM
  4. non-static member error
    By noob2c in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2003, 04:44 PM
  5. linker error, using static member
    By Chiel in forum C++ Programming
    Replies: 6
    Last Post: 06-28-2003, 08:40 PM

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