Thread: Objects

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    16

    Objects

    I'm having a little trouble with syntax with my program and i need some help.
    Can anyone show me the syntax for calling a function from a class with an object as its paramter and the syntax for the function name in the class? i'm somewhat new and very bad at the syntax on passing parameters.

    Thanks,
    Dyn4sty
    error C2262: 'I' : cannot be destroyed

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    16
    i get this error

    error C2664: 'Poly::addPoly' : cannot convert parameter 1 from 'Poly *' to 'Poly'
    error C2262: 'I' : cannot be destroyed

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dyn4sty22 View Post
    Can anyone show me the syntax for calling a function from a class with an object
    The same as any other function.
    Function_name(arguments);

    as its paramter and the syntax for the function name in the class?
    That's a little unambiguous. Do you care to try to re-explain that?

    Quote Originally Posted by dyn4sty22 View Post
    i get this error
    error C2664: 'Poly::addPoly' : cannot convert parameter 1 from 'Poly *' to 'Poly'
    That means the function expects an object of type Poly to be passed by value but you are trying to pass a pointer.
    If you have an object, you may be trying to pass the address:
    Code:
    void foo(Poly p) { }
    int main()
    {
        Poly mypoly;
        foo(&mypoly); // Wrong
        foo(mypoly); // Right
    
        // Or you may have a pointer
        Poly* pMyPoly = &mypoly;
        foo(pMyPoly); // Wrong
        foo(*pMyPoly); // Right. Dereference first.
    }
    Hope that helps.
    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.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by dyn4sty22 View Post
    I'm having a little trouble with syntax with my program and i need some help.
    Can anyone show me the syntax for calling a function from a class with an object as its paramter and the syntax for the function name in the class? i'm somewhat new and very bad at the syntax on passing parameters.
    What C++ book are you using? I'd recommend Thinking in C++, by Eckel. You can download it for free.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    class obj { int i; };
    
    class c
    {
        int class_func(obj o);
    };
    
    int main()
    {
        c my_class_instance;
        obj my_object;
    
        my_class_instance.class_func(my_object);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. most efficient way to write filestream objects?
    By darsunt in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2009, 05:17 PM
  2. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM