Vector does not keep values?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 669 Views - Last Post: 04 January 2013 - 10:37 AM Rate Topic: -----

#16 jimblumberg  Icon User is online

  • member icon


Reputation: 4025
  • View blog
  • Posts: 12,421
  • Joined: 25-December 09

Re: Vector does not keep values?

Posted 04 January 2013 - 09:52 AM

I suggest you read the documentation for your IDE and increase the compiler warning levels. Here are some of the error my compiler issues, without any increase in warning levels.

Quote

Equip.h||In member function ‘std::string Equip::getName()’:|
Equip.h|46|warning: statement has no effect [-Wunused-value]|
Equip.h|47|warning: no return statement in function returning non-void [-Wreturn-type]|
Equip.h||In member function ‘Equip Equip::loadEquip(int)’:|
Equip.h|79|error: ‘atoi’ was not declared in this scope|
Item.h||In member function ‘int Item::getId()’:|
Item.h|24|warning: statement has no effect [-Wunused-value]|
Item.h|25|warning: no return statement in function returning non-void [-Wreturn-type]|
Item.h||In member function ‘std::string Item::getName()’:|
Item.h|27|warning: statement has no effect [-Wunused-value]|
Item.h|28|warning: no return statement in function returning non-void [-Wreturn-type]|
Item.h||In member function ‘int Item::getHp()’:|
Item.h|30|warning: statement has no effect [-Wunused-value]|
Item.h|31|warning: no return statement in function returning non-void [-Wreturn-type]|
Item.h||In member function ‘int Item::getMp()’:|
Item.h|33|warning: statement has no effect [-Wunused-value]|
Item.h|34|warning: no return statement in function returning non-void [-Wreturn-type]|
Item.h||In member function ‘int Item::getQnt()’:|
Item.h|36|warning: statement has no effect [-Wunused-value]|
Item.h|37|warning: no return statement in function returning non-void [-Wreturn-type]|
Misc.h||In member function ‘Misc Misc::loadMisc(int)’:|
Misc.h|43|error: ‘atoi’ was not declared in this scope|
Bag.h||In member function ‘Item Bag::loadItem(int)’:|
Bag.h|176|error: ‘atoi’ was not declared in this scope|
Player.h||In constructor ‘Player::Player()’:|
Player.h|43|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
Monster.h||In member function ‘Monster Monster::loadMonster(int)’:|
Monster.h|55|error: ‘atoi’ was not declared in this scope|
Jogo.cpp||In function ‘int getRandom(int, int)’:|
/home/jim/Working/homework/c++/monsters/Jogo.cpp|27|error: ‘GetTickCount’ was not declared in this scope|
/home/jim/Working/homework/c++/monsters/Jogo.cpp|27|error: ‘srand’ was not declared in this scope|
/home/jim/Working/homework/c++/monsters/Jogo.cpp|28|error: ‘rand’ was not declared in this scope|
/home/jim/Working/homework/c++/monsters/Bag.h||In member function ‘Misc Bag::findMisc(int)’:|
/home/jim/Working/homework/c++/monsters/Bag.h|84|warning: control reaches end of non-void function [-Wreturn-type]|
/home/jim/Working/homework/c++/monsters/Bag.h||In member function ‘Item Bag::findItem(int)’:|
/home/jim/Working/homework/c++/monsters/Bag.h|72|warning: control reaches end of non-void function [-Wreturn-type]|
/home/jim/Working/homework/c++/monsters/Bag.h||In member function ‘Equip Bag::findEquip(int)’:|
/home/jim/Working/homework/c++/monsters/Bag.h|55|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 7 errors, 16 warnings ===|

You need to fix all of these warnings and errors.

When I have a few more warnings enabled:
Spoiler

Quote

||=== Build finished: 8 errors, 152 warnings ===|

As you can see a few more issues.

Jim
Was This Post Helpful? 1
  • +
  • -

#17 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2102
  • View blog
  • Posts: 3,207
  • Joined: 21-June 11

Re: Vector does not keep values?

Posted 04 January 2013 - 10:05 AM

As I said already:

View Postsepp2k, on 04 January 2013 - 04:16 PM, said:

You should enable (and read) warnings for your code. Your getter methods don't have any return statements (which you definitely will get warnings about if they're enabled), so calling them will invoke undefined behavior, causing the random values you're seeing.


PS: You shouldn't put all your code in your header files.
Was This Post Helpful? 0
  • +
  • -

#18 lscorpionlmi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 04-January 13

Re: Vector does not keep values?

Posted 04 January 2013 - 10:37 AM

Thanks it's solved, just missed some code.

I thought that warning levels were default, didn't knew i could raise its level.

Really thanks
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2