Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [C++ Help] Question about Switch-Case statement
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Shinobu




PostPosted: Tue Sep 03, 2013 8:22 pm   Post subject: [C++ Help] Question about Switch-Case statement

So to use a switch-case statement, it's kinda like this:
c++:
switch (variable)
{
case "stuff":
        {
                //Code here
        }
case "more stuff here":
        {
                //More code here
        }
}

But can I insert code before the cases like this?
c++:
switch (variable)
{
        //Do stuff
case "stuff":
        {
                //Code here
        }
case "more stuff here":
        {
                //More code here
        }
}


It would be awesome if I can; I want to deallocate the pointer I'm using for the switch-case statement.
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Tue Sep 03, 2013 11:30 pm   Post subject: Re: [C++ Help] Question about Switch-Case statement

You can probably place code there, but it will never execute since the switch will bring you to the appropriate case, avoiding the code.

I'm not sure what your doing that requires you to deallocate a pointer in the switch block but there is probably an alternative. Perhaps some more context would help?
Shinobu




PostPosted: Wed Sep 04, 2013 6:15 pm   Post subject: Re: [C++ Help] Question about Switch-Case statement

Dreadnought @ September 3rd 2013, 11:30 pm wrote:
You can probably place code there, but it will never execute since the switch will bring you to the appropriate case, avoiding the code.

I'm not sure what your doing that requires you to deallocate a pointer in the switch block but there is probably an alternative. Perhaps some more context would help?


Actually, nevermind about it.
I'm not going to try and save 1 byte of memory lol. Whatever XD
I was just trying to delete the variable that holds what the user inputs in my program, which is used in the switch-case.
Insectoid




PostPosted: Sat Sep 07, 2013 8:03 pm   Post subject: RE:[C++ Help] Question about Switch-Case statement

You could just delete the variable right after the switch executes. If you're not allocating anything inside the switch, then it's not saving any RAM (and even then you're probably not saving anything).
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: