S
S
Sticky Rain2020-10-24 20:08:15
C++ / C#
Sticky Rain, 2020-10-24 20:08:15

Trouble with Vector?

Help a noob figure out what the problem is...

#include <iostream>
#include <string>
using namespace std;

int main()
{
  struct Vector {
    Vector v;
    float x, y, z;
    v.x=15, v.y=25, v.z=35;
    cout << v.x << endl;
  };
  
  system("pause");
  return 0;
}


In console:
  1. 'v' has incomplete type 'main()::Vector'
  2. 'v' does not name a type
  3. 'cout' does not name a type

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Zhuravlev, 2020-10-24
@stiicky

#include <iostream>
#include <string>
using namespace std;

struct Vector {
    float x, y, z;
  };
  
int main()
{
    Vector v;
    v.x=15, v.y=25, v.z=35;
    cout << v.x << endl;
    system("pause");
    return 0;
}

Compare.
Mistakes: you call output to the stream in a structure, declare an instance of your structure in the same structure.
Look, declare a structure (in your case, Vector), enter fields in it (in your case, x, y, z).
After that, in the function, you already declare an instance of your structure and fill in the fields you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question