POV-Ray : Newsgroups : povray.off-topic : c++ template types for function : Re: c++ template types for function Server Time
20 Oct 2021 13:10:39 EDT (-0400)
  Re: c++ template types for function  
From: jr
Date: 30 Apr 2020 15:45:00
Message: <web.5eab2a15ce0a4398898043f30@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> "jr" <cre### [at] gmailcom> wrote:
>
> > no C++, but in C I'd create an array of a union of float + bool.
>
> I think for my purposes, c and c++ are similar enough to "be the same".
> {GASP!}  {Sacrilege!}  "Thou hast besmirched the pedantic purity of the names!"}

too much alike, visually, imo.

> Could you possibly write a little example of that in C so I can see how it
> works?

typedef union foo foo;
union foo {
  float f;
  bool b;
};

static foo fooarray[N];

in your case, the vector would be made of type foo; the typedef isn't needed,
just a convenience to use 'foo' in place of 'union foo'.  (no idea about syntax
etc)

> I also have a hardware address hard-coded into a .h file which prototypes the
> functions that interact with the hardware.
> The problem I have is that I need at least 2 different sensors, which will have
> different addresses once I switch one on the solder pad.  I can do a max of 4.
>
> Should I have 4 different .h files?
> Should I have 4 differently named constructors IN the .h file?
>
> I'm also confused about the associated .cpp file.  That's the one that actually
> has the functions defined in it, so how does #include <filename.h> access what's
> in filename.cpp if there's no #include <filename.cpp> in filename.h?
> Is it just an internal thing to the IDE that automatically includes any
> similarly named .cpp file if a .h file is included?

yes, I recently installed one of those C++ library-in-a-header files.  not my
cup of tea.

as regards the first question, I should have thought that, for a small project,
you can have all sensor constants etc in a single header, just a matter of
avoiding name clashes.


regards, jr.


Post a reply to this message

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.