1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Please help with a class construction

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

  1. rikar

    rikar New Member

    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