Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ template help?

Name: Anonymous 2007-02-04 0:44

In the following program I want g() to be prototyped inside the class X and defined later.  I can't get g() to compile though no matter how many variations I try.  f() compiles fine.

template <typename T>
class X
{
public:
    class Y { };
    Y f() {Y y; return y;} //Okay function.
    Y g(); //Problematic function.
};

//Compiler Error Here: expected constructor, destructor, or type conversion before 'X'
template <typename T>
X<T>::Y X<T>::f()
{
    Y y;
    return y;
}


int main()
{
    X<int> x;
    x.f(); //This works.
    x.g(); //Call to problematic function.
}

Name: Anonymous 2007-02-06 6:53

>>16
If you have no idea of what a dynamic language is supposed to do, don't claim C++ is a dynamic language. eval evals code. You can feed eval code in some way (some kind of code tree or object, or just a string of source code) and eval will execute it. You may have options to choose in what namespace you want it to run and such. Within eval, you can do anything you can do outside, like defining new classes, altering class hierarchy, and using eval itself.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List