#include <iostream>

using namespace std;

class test
{
    public:
    int bla(int &c);
};

int test:: bla(int &c)
{
    c=100;
    return c;
}

int main()
{
   int c=10;
   test student;
   int b=1;
   switch(b)
   {
       case '1': cout<<student.bla(c); break;
   }
   cout<<c;
   return 0;
}

I would like to change the variable c within the switch/case-lines, but it doesn't work, probably because of a problem with the scope.
Maybe someone could help me to solve this problem? Many thanks.

I'm guessing that ..

//// Instead of ..
// case '1': cout<<student.bla(c); break;

// .. you probably want to have ..
case 1: cout<<student.bla(c); break;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.