user1193256
user1193256

Reputation: 43

std::vector<std::vector<Vertex>> vertex_matrix; was not declared in this scope

In one .cpp file, I declare and implement a class "Vertex". Then I declare and implement second class "ThreeDimensionObject". Inside ThreeDimensionObject , it has one public member std::vector> vertex_matrix;

I did import . The project runs fine on xCode IDE and g++ prompt me "error: ‘vertex_matrix’ was not declared in this scope".

How can I fix it?

#include <vector>
class Vertex : public std::vector<float>
{
   //implementation
};

class ThreeDimensionObject
{
    //the center position
public:  
    //num_stack * num_stack * 4
    std::vector<std::vector<Vertex>> vertex_matrix;
};

Upvotes: 0

Views: 1808

Answers (2)

jxh
jxh

Reputation: 70412

The code compiles fine on IDEONE when compiled as . When compiled without the C++.11 flags, the code emits the following error:

prog.cpp:12:35: error: ‘>>’ should be ‘> >’ within a nested template argument list
     std::vector<std::vector<Vertex>> vertex_matrix;

This error probably occurred near the top of your list of errors, and you may not have seen it. You can compile the code as C++ 11 (by adding -std=gnu++11 or -std=c++11 to the g++ command line), or you can add the needed space.

    std::vector<std::vector<Vertex> > vertex_matrix;

Upvotes: 2

shofee
shofee

Reputation: 2129

The defination of 'vertex_matrix' should be,

std::vector<std::vector<Vertex> > vertex_matrix;

Your code compiles with c++11 flag but without c++11 flag it needs an extra space.

Upvotes: 1

Related Questions