Results 1 to 2 of 2

Thread: declaring inside an if...

  1. #1
    Member Contributor
    Join Date
    Oct 2002
    Posts
    55

    declaring inside an if...

    alright, i know this is a C++ question, but i like u guys here, and you help quickly =P
    alright, i have a program i have to make for school... but im stuck, i have a menu (cout << enter number....; cin >> choice;" right, and i have an if right after that for which choice they made...
    i have a class called "MyVec, and i have overloaded it, so i can pass MyVec Vect(); MyVec Vect(x); MyVec Vect(x,y);... this is based off the choice (1,2,3)...
    if its one, i want to just go "MyVec Vect();" if 2: "MyVec Vect(x)" etc.
    the problem is, when i declare them INSIDE the if statements, then they are LOCAL TO THE IF!!! in other words, i cant pass them anyplace else...
    anyone wanna help me?

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: declaring inside an if...

    MyVec *vec;

    switch(blah)
    {
    case 1:
    vec = new MyVec();
    break;
    case 2:
    vec = new MyVec(bleh);
    break;
    ...
    }

Similar Threads

  1. Declaring vertex attribute as ivec4
    By Vexator in forum OpenGL: GLSL
    Replies: 2
    Last Post: 06-23-2011, 05:59 PM
  2. Declaring Vertices
    By Flotonic in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-24-2011, 03:04 PM
  3. forward declaring functions
    By knackered in forum OpenGL: GLSL
    Replies: 12
    Last Post: 02-01-2006, 01:02 AM
  4. declaring identifiers
    By jofoxy in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-24-2004, 02:31 PM
  5. Declaring extension usage
    By ET3D in forum OpenGL: General
    Replies: 4
    Last Post: 05-24-2001, 01:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean