Pass arguments to a parameter class object

Posted by David R on Stack Overflow See other posts from Stack Overflow or by David R
Published on 2010-05-16T07:01:19Z Indexed on 2010/05/16 7:10 UTC
Read the original article Hit count: 171

This is undoubtedly a simple question. I used to do this before, but it's been around 10 years since I worked in C++ so I can't remember properly and I can't get a simple constructor call working.

The idea is that instead of parsing the args in main, main would create an object specifically designed to parse the arguments and return them as required.

So: Parameters params = new Parameters(argc, argv) then I can call things like params.getfile()

Only problem is I'm getting a complier error in Visual Studio 2008 and I'm sure this is simple, but I think my mind is just too rusty.

What I've got so far is really basic:

In the main:

#include "stdafx.h"
#include "Parameters.h"

int _tmain(int argc, _TCHAR* argv[])
{
Parameters params = new Parameters(argc, argv);

return 0;
} 

Then in the Parameters header:

#pragma once

class Parameters
{
 public:
Parameters(int, _TCHAR*[]);
~Parameters(void);
};

Finally in the Parameters class:

include "Stdafx.h"
#include "Parameters.h"

Parameters::Parameters(int argc, _TCHAR* argv[])
{

}

Parameters::~Parameters(void)
{
}

I would appreciate if anyone could see where my ageing mind has missed the really obvious.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++