Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Please help with a class construction (http://www.go4expert.com/forums/help-class-construction-t14360/)

rikar 4Oct2008 16:29

Please help with a class construction
 
Hi guys,
I am a beginner in C++, but I've got to implement as simple a class as possible to pass the test case below:
Code:

#include <iostream>
#include <string>
#include <assert.h>
class cVarCont
{
public:
        template <class T>
        void manage(const std::string& name, T& varRef)
        {
        }

public:
        void setValue(const std::string& namedVariable, const std::string& value)
        {
        }
};
int main()
{
        cVarCont nvc;
        int myInt(0);
        double myDouble(0.);
        std::string myString("");

        nvc.manage("int", myInt);
        nvc.manage("dbl", myDouble);
        nvc.manage("str", myString);

        nvc.setValue("int", "43");
        nvc.setValue("dbl", "123.8");
        nvc.setValue("str", "hello");

        std::cout << myInt << std::endl;
        std::cout << myDouble << std::endl;
        std::cout << myString << std::endl;
        std::cout<<"Hello World\n";

        assert(myInt==43);
        assert(myDouble==123.8);
        assert(myString=="hello");
        return 0;
}

And do not use a void pointer.
I appreciate any hints on this.
Thanks.


All times are GMT +5.5. The time now is 18:50.