Sign in to follow this  
Tallun

Member Constants and Objects Containing Other Objects of Their Class

Recommended Posts

  I have two questions both pertaining to my current project:   I'm trying to write my current project such that it is valid both in Visual C++ 6.0 and in Visual C++ 2005. One thing that doesn't seem to port over is the following declaration when inside of a class declaration: static const int JUST_SOME_CONSTANT = 100;   This works fine in 2005 but 6.0 thinks I'm trying to declare a pure virtual function, but at the same time is telling me that I should set it to 0 instead of whatever number I'm trying to set it to. How would I make this declaration in 6.0?   The other question is more asking suggestions. What is a good way to store in an object other objects of the same class and have functions that access these objects by their indexes or tags (tag being a property designated upon creation)? I can't seem to figure out a way to do this without having an assembly error.   Anything on either of these questions would be appreciated.

Share this post


Link to post
Share on other sites
Quote:
I'm trying to write my current project such that it is valid both in Visual C++ 6.0 and in Visual C++ 2005.


Short answer is that 6 is not standard C++ and is MS's best guess of the standard when it was released.

Share this post


Link to post
Share on other sites
You maybe could do it in a way, but why would you want to adjust your code to fit something which is broke?


Quote:
What is a good way to store in an object other objects of the same class and have functions that access these objects by their indexes or tags (tag being a property designated upon creation)?


Can you give me an example.
Maybe??? By having a class which "has a" other class
ie

class door{};
class car
{
...
std::vector<door*> the_doors;
}


Share this post


Link to post
Share on other sites
Quote:
You maybe could do it in a way, but why would you want to adjust your code to fit something which is broke?

  I downloaded the Express Edition of Visual C++ 2005 for one of the computers that I do my programming on. However, the other doesn't have an internet connection and only has Visual C++ 6.0. I'm trying to be able to work on my project on both computers. Actually, it isn't that important, I suppose. I'd just like to know how Visual C++ 6.0 does member constant declarations if it does.

Quote:
Can you give me an example.

  I have a class (let's call it MyClass for this example) which needs to contain other MyClass objects to form a hierarchy of MyClass objects. It needs also to be able to refer to the MyClass objects contained within through such functions as GetByIndex(), which will accept an integer parameter and return the MyClass object within the calling MyClass object at the specified index, assuming the index is valid. The function isn't important now, however; what's important is a method of storing MyClass objects within a MyClass object.

  Edit:Come to think of it, I haven't tried vectors yet. I'll try that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Tallun
  I downloaded the Express Edition of Visual C++ 2005 for one of the computers that I do my programming on. However, the other doesn't have an internet connection and only has Visual C++ 6.0. I'm trying to be able to work on my project on both computers. Actually, it isn't that important, I suppose. I'd just like to know how Visual C++ 6.0 does member constant declarations if it does.

VC++ 6.0 is old and relatively broken (even after 6 patches). MS no longer supports it. You should replace it. You can copy the VS 2005 installation package to a CD and install it from the CD. In the meantime, constants can be done in VC++ 6.0 using enum or #define.

Quote:
Original post by Tallun
  Edit:Come to think of it, I haven't tried vectors yet. I'll try that.

A vector will work just fine.

Share this post


Link to post
Share on other sites
As an alternative to copying and installing you could have a pen drive with a portable version of dev cpp (instuctions found at http://www.portablefreeware.com/?id=417). My file size for this is about 105mb, but I have the following API's
DirectX
Win32
Lua
OpenGL
OpenAL
SDL

Not the smallest of portable apps but fully self contained.

"...hierarchy of MyClass objects..." To me this sounds like you are describing a container like list, array , vector,.
have a look at the image at the bottom of
http://linuxsoftware.co.nz/cppcontainers.html

Share this post


Link to post
Share on other sites
Quote:
You can copy the VS 2005 installation package to a CD and install it from the CD.

  Actually, immediately after my last post yesterday I decided to try and transport the installer to the other computer. It took only a small hassle (and I didn't want to use a CD for the file's small size), but it took long enough that I didn't get enough time to attempt to install it yesterday, which I'll try today. I have some doubts that it will work; the computer is running under Windows 98.

Quote:
As an alternative to copying and installing you could have a pen drive with a portable version of dev cpp (instuctions found at http://www.portablefreeware.com/?id=417).

  I have DevC++ but I don't like it. I don't remember the exact reasons why I stopped using it, but I'd prefer not to use it.

  Anyway, my questions in this thread are basically answered, so I'll just post whether it worked in a moment and that should do it. Thanks for your help.

  Edit: It didn't work. Maybe I should use DevC++.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this