0

My last c++ Project was about 3 years ago and know I have some problems with basics.

I have a class stuff. In my .h file i have a struct:

typedef struct
{
  float fX;
  float fY;
  float fZ;
  float fRx;
  float fRy;
  float fRz;
  char aName[14] = "";
} stpoint;

and a private variable stpoint _stpoints[].

In my.cpp I have a function:

void stuff::getstuff()
{
  stpoint _stpoints[] = {
    { 164.5, 0.0, 241.0, 90.0, 180.0, -90.0,"Home"},
    { 164.5, 0.0, 141.0, 90.0, 180.0, -90.0,"X1"},
    { 164.5 + 14.7, 35.4, 141.0, 90.0, 180.0, -90.0 ,"X11"},
    { 164.5 + 50.0, 50.0, 141.0, 90.0, 180.0, -90.0,"X12"},
    { 164.5 + 85.3, 35.4, 141.0, 90.0, 180.0, -90.0,"X13"},
    { 164.5 + 100.0, 0.0, 141.0, 90.0, 180.0, -90.0,"X14"},
    { 164.5 + 85.3, -35.4, 141.0, 90.0, 180.0, -90.0,"X15"},
    { 164.5 + 50.0, -50.0, 141.0, 90.0, 180.0, -90.0,"X16"},
    { 164.5 + 14.7, -35.4, 141.0, 90.0, 180.0, -90.0,"X17"},
    { 164.5 + 50.0, 0.0, 141.0, 90.0, 180.0, -90.0,"X18"},
    { 264.5, 0.0, 141.0, 0.0, 90.0, 0.0 ,"X2"},
    { 164.5, 100.0, 141.0, 90.0, 90.0, 0.0,"X3"},
    { 164.5, -100.0, 141.0, 90.0, -90.0, 0.0,"X4"}
  };
}

Its a project for Arduino. I use VS2019.

I get error code (just one of them):

stuff.cpp: 37:2: error: could not convert '{1.645e+2, 0.0, 2.41e+2, 9.0e+1, 1.8e+2, -9.0e+1, "Home"}' from '' to 'stuff::stpoint
Error compiling project sources
Debug build failed for project 'Roboter'

It something about the char array in the struct but i dont get it :(

struct stpoint _stpoints2 = { 164.5, 0.0, 241.0, 90.0, 180.0, -90.0,"Home"} gives the same error.

ocrdu
  • 2,172
  • 6
  • 15
  • 22
Razer1337
  • 11
  • 4
  • Please produce a minimal example that demonstrate the problem. Your typedef is `stpoint` from the error message is about `stuff::stpoint`. gcc complains about the the "" default value and seem happier with {""}. Also see https://stackoverflow.com/questions/24741237/initializing-a-char-in-struct-in-c – Allan Wind Dec 28 '20 at 01:17
  • 1
    https://stackoverflow.com/questions/11643844/how-to-initialize-a-char-array-inside-a-class might be relevant too. – Allan Wind Dec 28 '20 at 01:23
  • hey that solved my problem thanks – Razer1337 Dec 28 '20 at 13:17

2 Answers2

0

@πάντα ῥεῖ

 typedef struct
 {
     float fX;
     float fY;
     float fZ;
     float fRx;
     float fRy;
     float fRz;
     char aName[14];
 } stpoint;

that solved the problem. thanks

Razer1337
  • 11
  • 4
0

Initialize with aName = { "" }.

Allan Wind
  • 23,068
  • 5
  • 28
  • 38