How to use constructor list passing an array
-
Could somebody please correct this code for me ? I am trying to pass char array to a constructor and USE LIST to initialize the class variable. I can do single char - USING LIST - no problem, I can pass a variable and copy it to class variable. I am trying to learn more about using LIST AND I am hopelessly lost how to pass a char array - preferably "by pointer". I have tried all kinds of syntax combinations, samples etc. but I really need some help. Appreciate any inputs.
// passing an array of char char array\[16\]; public: CLASS\_SPI\_NEW(char array): array(array) { }
-
Could somebody please correct this code for me ? I am trying to pass char array to a constructor and USE LIST to initialize the class variable. I can do single char - USING LIST - no problem, I can pass a variable and copy it to class variable. I am trying to learn more about using LIST AND I am hopelessly lost how to pass a char array - preferably "by pointer". I have tried all kinds of syntax combinations, samples etc. but I really need some help. Appreciate any inputs.
// passing an array of char char array\[16\]; public: CLASS\_SPI\_NEW(char array): array(array) { }
Vaclav_ wrote:
<pre lang="c++"> // passing an array of char char array[16]; public: CLASS_SPI_NEW(char array): array(array) { }</pre>
Did you probably mean
CLASS_SPI_NEW(char* array): array(array)
-
Vaclav_ wrote:
<pre lang="c++"> // passing an array of char char array[16]; public: CLASS_SPI_NEW(char array): array(array) { }</pre>
Did you probably mean
CLASS_SPI_NEW(char* array): array(array)
Thanks for the suggestion , here is what I did and it works. Two more questions The array actually gets filed with 12 characters and I have "sized" it for two. This "list constructor " code syntax have no "prototype", but it works.
char \*array = " "; int channel; long speed; int mode; C\_SPI\_NEW(char \*array, int channel, long speed, int mode ) : array(array), channel(channel), speed(speed), mode(mode) { #ifdef DEBUG cout << "\\033\[1;31mConstructor \\033\[0m\\n"; cout <<" device " << array <
-
Thanks for the suggestion , here is what I did and it works. Two more questions The array actually gets filed with 12 characters and I have "sized" it for two. This "list constructor " code syntax have no "prototype", but it works.
char \*array = " "; int channel; long speed; int mode; C\_SPI\_NEW(char \*array, int channel, long speed, int mode ) : array(array), channel(channel), speed(speed), mode(mode) { #ifdef DEBUG cout << "\\033\[1;31mConstructor \\033\[0m\\n"; cout <<" device " << array <
Is there some very important reason to use plain char array instead of std::string or MFC CString class?
-
Is there some very important reason to use plain char array instead of std::string or MFC CString class?
Yes, but it is complicated. Since you asked- I am using PC to remotely compile C++ code for Raspberry Pi. No MFC needed. My OS is Ubuntu and my IDE is Eclipse. I have no problem using String on PC locally, but the OS on Raspberry Raspbian complains about wrong version of some library. When I check the version in question it is current. Instead of trying to figure out something over my head I simply do no use String. My application is pretty much "low level bits" communication anyway. Problem solved.