Thread: A few beginner's questions

  1. #31
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So you have the declaration right, you just have to not stop. Just as the name itself is a declaration
    Code:
    int foo(int x); //function declaration
    so is the name itself a declaration.
    Code:
    class Foo; //class declaration

  2. #32
    Registered User Megidolaon's Avatar
    Join Date
    Oct 2008
    Posts
    8
    This is also incorrect. The correct syntax to call a static method is:
    attack::use
    I see and why do I need the ' :: ' operator?
    When do I need this and when do I need the ' . ' operator?

    But A does not store an object of B, so the definition of B is only needed when defining A::doNothing. C_ntua's point is that that is one example where defining the member function inline will not work, but defining it outside of the class definition will work, assuming that a forward declaration of B is used before defining A. Admittedly, I did not consider this possibility.
    I just tested it, it won't work.
    If I don't declare class B above class A, I can't have a method in class A that uses class B. Even if I only declare the method in the class and define the body of the method below both classes, I get an error.
    This is pretty tricky and will probably cause me headaches in the future.

    And when creating a library, I'd just put the definitions of these methods below the class, while still in the same namespace?

    As for the methods taking references to an object, I forgot that you can just add * and & to a variable call.
    In this case, I'd make a method which takes a memory address of an object and pass that to the method, like this?
    Code:
    void Test(Object& obj) 
    {
         // Do Stuff
    }
    
    . . .
    
    Object obj;
    
    Test(&obj);
    
    . . .

  3. #33
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    attack::use() means "call the member function use in CLASS attack". If you instead have attack.use() it means "call the member function use in the OBJECT attack".

    A static member function is one that can be used without actually having an object of that class. It is a way to have functions that doesn't actually work on an object, but still belongs to the class in some way.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Megidolaon View Post
    Code:
    void Test(Object& obj) 
    {
         // Do Stuff
    }
    
    . . .
    
    Object obj;
    
    Test(&obj);
    
    . . .
    It is...
    Code:
    void Test(Object& obj) 
    {
         // Do Stuff
    }
    
    Object obj;
    Test(obj);
    ...or...
    Code:
    void Test(Object* obj) 
    {
         // Do Stuff
    }
    
    Object obj;
    Test(&obj);
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner's Questions
    By bjl in forum C++ Programming
    Replies: 4
    Last Post: 01-31-2008, 06:56 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM