Command line arguments problem

Hey everyone,

I'm working on a project for my Computer Science class and I'm having a problem taking in these command line arguments.

I get the error

bash-3.00$ g++ water.cpp
water.cpp: In function `int main(int, char**)':
water.cpp:28: error: invalid conversion from `Config*' to `int'
water.cpp:28: error: initializing argument 1 of `Config::Config(int)'
water.cpp:29: error: invalid conversion from `Config*' to `int'
water.cpp:29: error: initializing argument 1 of `Config::Config(int)'

What is going on??

Code below:

main:

#include <iostream>
#include "Solver.h"
#include "Water.h"
#include "Config.h"
#include <list>

using namespace std;

int main( int argc, char* argv[] ) {

Solver s;
list<Config> initialConfigs;
list<Config> maxConfigs;
Config goal( atoi( argv[1] ) );

for( int i = 2; i != argc; i++ ) {
int temp = atoi( argv[i] );
initialConfigs.push_front( new Config( 0 ) );
maxConfigs.push_front( new Config( temp ) );

}

Water* w = new Water( initialConfigs, maxConfigs, goal);

And my config class is:

#ifndef CONFIG_H
#define CONFIG_H

class Config {
public:
Config( int init );
int getConfig();
void setConfig( int init );
bool isEqual( Config *c );
private:
int _init;

};

#endif
[1651 byte] By [standmatt] at [2007-11-20 11:33:23]
# 1 Re: Command line arguments problem
The problem is here:
initialConfigs.push_front( new Config( 0 ) );
maxConfigs.push_front( new Config( temp ) );
new Config(0) and new Config(temp) return Config*, not Config. But initialConfigs and maxConfigs are of type std::list<Config>, not std::list<Config*>. Most likely you just want to write:
initialConfigs.push_front( Config( 0 ) );
maxConfigs.push_front( Config( temp ) );
laserlight at 2007-11-9 1:25:53 >
# 2 Re: Command line arguments problem
Or simply initialConfigs.push_front( 0 );
maxConfigs.push_front( temp );Admittedly this does not necessarily improve readability - you can forbid such code by declaring the constructor as explicit.
treuss at 2007-11-9 1:26:53 >