Hi folks,

First a bit of context (Errors are shown at the bottom of the post):
I am creating an object viewer for opengl in Visual C++ 2008 Express Edition. I have written a parser which reads the file and stores all the info I want in a Mesh object.

A Mesh consists of a vector of Polygons, a vector<vector<float>> of normal vectors, and a vector of Vertices (Ver).

Mesh.h:

#ifndef GUARD_Mesh_h
#define GUARD_Mesh_h

#include<iostream>
#include <vector>
#include "Polygon.h"
#include "Ver.h"


class Mesh {

public:
	
	// ATTRIBUTES
	int num_vertices;	
	std::vector<Ver> vertices;

	int num_normals;
	std::vector<std::vector<float>> normals;

	int num_polygons;
	std::vector<Polygon> polygons;

	// CONSTRUCTORS
	Mesh();
	Mesh(int, std::vector<Ver>);
	Mesh(int, std::vector<Polygon>);
	Mesh(int, std::vector<Ver>, int, std::vector<Polygon>);
	Mesh(int, std::vector<Ver>, int, std::vector<Polygon>, int, std::vector<std::vector<float>>);

	// ACCESSORS
	int get_num_vertices() const;
	Ver get_vertex(int) const;

	int get_num_polygons() const;
	Polygon get_polygon(int) const;

	int get_num_normals() const;
	std::vector<float> get_normal(int) const;

	// MANIPULATORS
	void set_vertices(int, std::vector<Ver>);
	void set_normals(int, std::vector<std::vector<float>>);
	void set_polygons(int, std::vector<Polygon>);

};

#endif

A Polygon is a vector of ints, which denote indices to vertices stored in the vector of Vertices in the Mesh.

Polygon.h:

#ifndef GUARD_Polygon_h
#define GUARD_Polygon_h

#include <iostream>
#include <vector>

class Polygon {
public:
	// ATTRIBUTES
    // vertex indices
	std::vector<int> vertices;

	// CONSTRUCTORS
	Polygon();
	Polygon(std::vector<int>);
	
	// ACCESSORS
	int get_index(int) const;

	// MODIFIERS
	void set_vertices(std::vector<int>);
};

#endif

A Ver is simply a coordinate, a vector<float>.

Ver.h:

#ifndef GUARD_Ver_h
#define GUARD_Ver_h

class Ver {
public:
	std::vector<float> v_coord;
	
	std::vector<float> get_coord() const;
	
	Ver();
	Ver(float, float, float);
	  
};

#endif

A 'Parser' class reads from a text file to create a Mesh. (GetIntVal just gets the int value from a string)

Parser.h:

#ifndef GUARD_Parser_h
#define GUARD_Parser_h

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
#include "GetIntVal.h"
#include "Polygon.h"
#include "Ver.h"
#include "Mesh.h"

using std::string;		using std::vector;		using std::ifstream;
using std::cerr;		using std::endl;		using std::cout;
using std::cin;			using std::istringstream;
using std::ios;

// Returns a string void ';' and ',' 
std::string trim(std::string str);


// Given an ifstream and number of vertices, reads vertex positions from file
std::vector<Ver> read_vertices(int vertex_count, std::ifstream& x_file);


// Given an ifstream and number of normals, reads normal vectors from file
std::vector<std::vector<float>> read_normals(int normal_count, std::ifstream& x_file);


// Given an ifstream and number of polygons, reads vertex indices for polygons
std::vector<Polygon> read_polygons(int polygon_count, std::ifstream& x_file);


// Identifies the vertices, polygons and normals of .X file, 
// @ returns Mesh populated with vertices, polygons and normals
Mesh read_mesh(std::ifstream& x_file);


Mesh load_x_file(const char* s);

#endif

The parser works fine when testing it within its own main function. The problem occurs when I try to use the parser elsewhere. I took NeHe tutorial 5 Visual C++ code ( http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05 ), the only modifications are removing the #include glaux, and replacing it with "#include "Parser.h". I didn't try to use any of the methods of Parser, I simply included it.

The following are the errors produced:

1>------ Build started: Project: Object_Viewer, Configuration: Debug Win32 ------
1>Compiling...
1>OpenGL_window.cpp
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(22) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(27) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(27) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(28) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(28) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(29) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(29) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(36) : error C2146: syntax error : missing ';' before identifier 'get_polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(36) : warning C4183: 'get_polygon': missing return type; assumed to be a member function returning 'int'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\mesh.h(44) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>c:\users\tom\documents\visual studio 2008\projects\object_viewer\object_viewer\parser.h(33) : error C2923: 'std::vector' : 'Polygon' is not a valid template type argument for parameter '_Ty'
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(4203) : see declaration of 'Polygon'
1>Polygon.cpp
1>Generating Code...
1>Build log was saved at "file://c:\Users\Tom\Documents\Visual Studio 2008\Projects\Object_Viewer\Object_Viewer\Debug\BuildLog.htm"
1>Object_Viewer - 12 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I'm assuming the errors I have caused here are rather abstract, hence only including the header files. Apologies if I've missed any relevant details.

Any help would be much apprecaited.

Tom

Recommended Answers

All 2 Replies

First of all let me apologize that I cannot give too much attention to your problem.

But the first thing that I would do would be to rename my Polygon class, since it looks like there are two classes with the same name.

Another thing that could be done would be to define a copy constructor for Polygon.

Hope this helps.

But the first thing that I would do would be to rename my Polygon class, since it looks like there are two classes with the same name.

Thank you, Thomas!

Changing the name of the Polygon class did the trick. I'll also hopefully be able to recognise these sorts of errors and know what to do next time!

Much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.