I suppose to do some unusual stuff. I have a class template:
template<class T> class CFile
I want to build another class which would have a member of int type,
class foo
{
private:
int memb;
}
when I pass the “foo” class as “< T >” to “CFile”, foo is supposed to simply act as integer. I need ideas how to implement it only with internal logic in foo, without changing CFile (CFile is not allowed to contain any logic which extracts the int member from the class).
It’s for a task in college, so I should not change the rules given to me. It should look like this:
class foo
{
int memb;
}
int main()
{
foo myFoo;
// The ctor of CFile takes a file path and opens the file. After that it can write
// members from type < T > to the file. I need the CFile to write the memb member to
// the file (Remember that the CFile is passed as < T >
CFile<foo> file("c:\\file.txt");
}
Thanks.
What I think you’re trying to do is for
class footo act as an integer. For this effect you need to provide:foofrom anint.fooclass to anint.You would have something like this: