>Provided I cannot make define the object globally or at the start of main().
You have to define a variable before it's used, and you have to define a variable within a visible scope. What you're doing is illegal because g1 is defined in a nested scope but used beyond that scope. It has to be like this:
int main()
{
// ...
Graph g1;
if ( var )
g1 = CreateGraph<Graph> ( vertex, edge );
else
g1 = CreateGraph<Graph1> ( vertex, edge );
numvertex ( g1 );
}
>Provided I cannot make define the object globally or at the start of main().
If the unnamed block trick doesn't count, you're SOL:
int main()
{
// ...
{
Graph g1;
if ( var )
g1 = CreateGraph<Graph> ( vertex, edge );
else
g1 = CreateGraph<Graph1> ( vertex, edge );
numvertex ( g1 );
}
}
However, I fail to understand why you have this restriction. Perhaps you can enlighten us as to what program requirements are stopping you from defining a variable in the correct scope?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>If you would look closely he has 2 different Graph classes apparently, Graph and Graph1
*sigh* I hate it when poor naming practices cause me to make a mistake.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401