Jump to content
СофтФорум - всё о компьютерах и не только

помогите с с++


Recommended Posts

#ifndef VEC4_H_

#define VEC4_H_

#include <iostream>

class Vec4

{

private:

float* vec;

public:

Vec4(int num);

float operator[](int num);

};

#endif

#include "vec4.h"

Vec4::Vec4(int num)

{

vec = new float[num];

for (int i = 0; i < num; i++)

vec = 0;

}

float Vec4::operator[](int num)

{

return vec[num];

}

#include "vec4.cpp"

int main()

{

Vec4 v4(4);

std::cin >> v4[2]; //error: no match for 'operator>>' in 'std::cin >> v4.Vec4::operator[](2)'|

std::cout << v4[2];

return 0;

}

возникает ошибка при попытке записать значение в массив объекта, типа не перегружена операция >>, но перегружена операция индексации и ведь по идее, v4[2] - уже имеет тип float, а не Vec4, почему происходит такой косяк?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...