Thread: A pointer to a type??

  1. #1
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120

    A pointer to a type??

    Is it possible to pass a pointer to a type as an argument to a function?

    e.g.

    Code:
    void Function(void *type)
    {
         type Variable;
    }
    Or something like that??
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is an object factory as Andrei Alexandrescu describes in Modern C++ Design.

    Code:
    typeplate <typename T, typename U>
    class A
    {
    ...
    T * CreateObject();
    };
    The code above is an example and requires much more modifications to solve your problem. Nonetheless, the concept is the same.

    Kuphryn

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    This seems to work:
    Code:
    template<class T>
    void Function(const T& obj)
    {
       T innerobj;
       // ... Other Stuff
    }

  4. #4
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    Cheers guys, I have a look :-)

    dt
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strings Vs. Char pointers
    By aijazbaig1 in forum C Programming
    Replies: 49
    Last Post: 02-13-2008, 09:51 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Another Linked List plee
    By Dragoncaster131 in forum C Programming
    Replies: 3
    Last Post: 05-15-2004, 05:40 PM