POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
4 Nov 2024 17:33:57 EST (-0500)
  Re: My first C++ program  
From: Slime
Date: 20 Sep 2008 01:13:53
Message: <48d48691$1@news.povray.org>
> What you could do, is have a function like DoOperation(stack,op), and use 
> "op" as a token for the operation.

>     if (cmd == "+") {DoOP(stack,0); continue;}
>     if (cmd == "-") {DoOP(stack,1); continue;}
>     if (cmd == "/") {DoOP(stack,2); continue;}
>     if (cmd == "*") {DoOP(stack,3); continue;}

This is good, but instead of using integers like 0 1 2 3, I'd use an enum:

enum Operation
{
    OP_ADD,
    OP_SUBTRACT,
    OP_DIVIDE,
    OP_MULTIPLY,
};

An enum gives meaning to this sort of approach so you don't have to remember 
what something like "2" means.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.