1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Please help with a class construction

Discussion in 'C' started by rikar, Oct 4, 2008.

  1. rikar

    rikar New Member

    Joined:
    Oct 4, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
    Last edited by a moderator: Oct 4, 2008

Share This Page