Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to use constructor list passing an array

How to use constructor list passing an array

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structurestutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    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)
    {
    
    }
    
    V 1 Reply Last reply
    0
    • V Vaclav_

      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)
      {
      
      }
      
      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      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)

      V 1 Reply Last reply
      0
      • V Victor Nijegorodov

        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)

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #3

        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 <
        
        V 1 Reply Last reply
        0
        • V Vaclav_

          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 <
          
          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Is there some very important reason to use plain char array instead of std::string or MFC CString class?

          V 1 Reply Last reply
          0
          • V Victor Nijegorodov

            Is there some very important reason to use plain char array instead of std::string or MFC CString class?

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups