cannot compile.... [c++]

Started by
20 comments, last by Kalten 15 years ago
That's no good idea either. Devcpp is buggy as well. If you don't mind using mingw and gdb for debugging, take a look into Code::Blocks.
-----PARPG - open source isometric 2d old school RPG still looking for interested contributors
Advertisement
In your class methods have you tried using the keyword 'this' before your private variables. this.name = nam; I'm not familiar enough with the older versions of the Microsoft IDE's to know if they're that picky or not. I had a similar problem once in a different language and putting the scope before the variable fixed it.
Quote:Original post by Nanook
decided to use dev-cpp instead.. we can use that aswell.. I guess we could use another version of vs too.. I'll ask my teacher why we use it at all..


dev-cpp isn't a good choice either as it is no longer supported and buggy. Ask your teacher if you can use VS 2005/2008, or if that isn't available I recommend code::blocks.
if I was you i would get vs 2008 pro which is free for student or discounted. The software is usually 1000 plus but for you it would be either free or 100 something. Later on you can dive into mfc which is nice to try out before finishing school. You cant work with mfc out side the vs 2008 retail version so express version doesnt have it
Bring more Pain
Yeah, syntactically the code is correct, at least on VS2008. I'm unsure what changes have been made since then.
Looking at your code, you are trying to access a private variable name from a "Unit" object passed into your method.
You will need to either declare that variable as public in your Unit.h file OR create a getter/setter method such as
public variable method
public: std::string name;

Getter/Setter method
public: std::string GetName(){return name;} void SetName(std::string nm){ name = nm;}private: std::string name;

The accepted best practice is to use the getter/setter method for each private variable rather than exposing a variable as public.
Hope that helps
Quote:Original post by mudrugger
Looking at your code, you are trying to access a private variable name from a "Unit" object passed into your method.
You will need to either declare that variable as public in your Unit.h file OR create a getter/setter method such as
public variable method
public: std::string name;

Getter/Setter method
public: std::string GetName(){return name;} void SetName(std::string nm){ name = nm;}private: std::string name;

The accepted best practice is to use the getter/setter method for each private variable rather than exposing a variable as public.
Hope that helps


That was my first thought too, without even looking at the code, but just by looking at the errors. I'm still learning myself, but I remember in one of the books that I had read about having these kinds of issues and to make sure you understand the difference.
Quote:Original post by Nanook
We got access to msdna through uni and I downloaded vs 6.0 from there so it might be that it got a more recent compiler implemented?


1) 6.0 is more than a decade old. In computer terms, that's paleolithic.
2) Current versions are available from Microsoft for free. You should be able to get them through MSDN, even.
Quote:Original post by Joshuad
Quote:Original post by mudrugger
Looking at your code, you are trying to access a private variable name from a "Unit" object passed into your method....

That was my first thought too, without even looking at the code, but just by looking at the errors.


That's what the 'friend' keyword, as used in unit.h, is for. :)
Yeah, I found out about dev-cpp being outdated.. and got code::blocks now.. I'll have to ask my teacher at uni.. maybe I've downloaded the wrong version or something.. but I think I'll stick to code::blocks for now.. got way to much work to get done befor I got time to experiment with different compilers right now :p

Thanks a bunch for your responses! :)

This topic is closed to new replies.

Advertisement