constructor list supplied at runtime vs before compiler
Example below - can I supply building_num{1200}, garages_num{23} at time of the call rather than before within the class definition?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class City
{
private:
int road_num;
int house_num;
int building_num;
int garages_num;
int streetlamps_num;
int array[5];
public:
//City(); {}!!!!!
City() : building_num{1200}, garages_num{23}, streetlamps_num{999}, array{4,3,7,3,100}
{
//nothing to do here
}
Not really. I want to pass some system values on to the constructor of a small routine that will analyze them. Hypothetically the values will be available after run time. I want to run the program, call the function to get the values, then pass those to the analysis subroutine with the constructor.
class City
{
private:
int road_num;
int house_num;
int building_num;
int garages_num;
int streetlamps_num;
int array[5];
public:
//City(); {}!!!!!
City() : building_num{1200}, garages_num{23}, streetlamps_num{999}, array{4,3,7,3,100}
{
//nothing to do here
}
In my example above building_num, garages_num, etc. are already known, no prob.
My program of concern checks for resolution of screen post-compile.
When it does that I want to pass it to an object for analysis. But how do I do this? I can't set up a constructor at this point can I?
I want to run the program, call the function to get the values, then pass those to the analysis subroutine with the constructor.
Well you can do that by passing the arguments to the constructor when you instantiate the object:
1 2 3 4 5 6 7 8 9 10
// next line is a function declaration
get_screen_data(unsignedint& height, unsignedint& width);
//function call
get_screen_data(height, width);
// ScreenAnalyizer class has a constructor which takes 2 arguments
//instantiate MyScreen object, calls ScreenAnalyizer constructor with arguments
ScreenAnalyizer MyScreen(height, width);
Your information allowed me to finally get a constructor working for my object, and it worked fine. Thank you. If you know anything about drawing in windows point me to the right direction, otherwise thanks !
IMO you would be much better off to use a modern GUI framework. There are a bunch of options - Qt , sfml probably others too.
Edit: Using something so old, is a bit like if you have a brand new car with Electronic Fuel Injection, but you want to retrofit a carburettor from a 1987 car :+(
ha ha. I found graphics.h, ended up going with SDL library though. Just wanted to draw a few lines -- it looks like some fun in doing it though. SDL way good 2D graphics though.thx