include "stdafx.h"
#include <iostream>
using namespace std;
class Foo{
public:
void func()
{
cout<<"Hello!!"<<endl;
}
};
void some_func(const Foo &f)
{
//f.func();
Foo &fr=const_cast<Foo&>(f);
fr.func();
}
int main()
{
some_func(Foo &f); //if const declared will add the no of errors from 2 to 3
return 0;
}
How to invoke the some_func(const Foo &f)...If i declare the const before Foo parameter in main it shows me error... But if i'm using the code above i'm getting 2 errors..
output:
1>------ Build started: Project: const_cast, Configuration: Debug Win32 ------
1>Compiling...
1>const_cast.cpp
1>c:\documents and settings\beata\my documents\visual studio 2008\projects\const_cast\const_cast\const_cast.cpp(24) : error C2065: 'f' : undeclared identifier
1>c:\documents and settings\beata\my documents\visual studio 2008\projects\const_cast\const_cast\const_cast.cpp(24) : error C2275: 'Foo' : illegal use of this type as an expression
1> c:\documents and settings\beata\my documents\visual studio 2008\projects\const_cast\const_cast\const_cast.cpp(8) : see declaration of 'Foo'
1>Build log was saved at "file://c:\Documents and Settings\beata\My Documents\Visual Studio 2008\Projects\const_cast\const_cast\Debug\BuildLog.htm"
1>const_cast - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========