0

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; }; 
1
  • As an unrelated side note, a std::vector is an incredibly awful way to represent a vertex in 3-space, as it uses a dynamically allocated block of memory for what should just be 3 or 4 floats (and that block takes up about as much additional overhead as those 4 floats themselves, not to forget the std::vector's automatic storage itself, that is also as large as the actual vertex data itself). If you really want a standard library container for vertices, then at least settle for a std::array. Commented Sep 18, 2013 at 9:29

2 Answers 2

2

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; 
Sign up to request clarification or add additional context in comments.

1 Comment

+1 Assuming the OP (or anyone else) uses the canned clang from Apple, to ensure C++11 compliance in Xcode, (1). Select the project in the solution, (2) Select All+Combined in the settings window, (3) Scroll to Build Options and select "Apple LLVM ..." for the compiler, (4) Scroll down to the "Apple LLVM 4.2 compiler - Language" settings and set the C++ Language Dialect setting to be "C++11 (-std=c++11)" That should do it. g++ settings are a little different, but in the same settings location of Xcode.
1

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.

1 Comment

Thank you! This works. I am working on school, which does not allow use c++ 11.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.