Problem compiling C++ class

I am running a C++ program which uses a class from another .cpp file. The class only has a constructor. It works when I test it separately. The main program compiles,but when I run it, I have a bug in the constructor. Any one can think of any situation that could happen? Thanks.

I guess I just run the code in terminal, and it is fine. But when I try to build a project in eclipse, it shows following code has multiple definition error:

class model
    int textures [];
    float vertices[][3];
    float triangles[][13];
    model(const char*); // constructor

model::model(const char* filename)

error message is: multiple definition of `model::model(char const*)'

any idea?


You need to split your code into a .h (header) and a.cpp (implementation) file and put:

model::model(const char* filename)

in the latter. Or, rewrite your class so the definition of the constructor (and any other member functions) is inside the class in the header file:

class model {
   model(const char*) {
     // constructor body here

Anyway, I'll venture a random guess (given what you've posted, there little to go on). I'll guess that you've overflowed your triangle array (perhaps counter is too big) and you're trashing your heap or stack.

One more thing. This line:

if (str[0] != '#' and !str.empty())

is buggy. If str is empty, you don't want to be reading str[0]. You need to switch the order around:

if (!str.empty() and str[0] != '#')

Need Your Help

Unit testing in Django: How to initialize database

python django unit-testing testing django-fixtures

I am trying to do Test Driven Development with Django. My problem is that I need to add some things in the database before running the tests, for instance a number of users, departments and their

C# Percent encode å to %C3%A5 based on RFC 5849 OAuth 1.0

c# ruby encoding

I am trying to Percent encode å to %C3%A5 based on RFC 5849 OAuth 1.0

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.