Question about objects/pointers and stack/heap

Hi, I'm studying 1st year game development and we have to program some stuff in C++

To make objects, so far we have always been taught to work with pointers.
for example:

Animal* animalPtr = new Animal(parameters);

however recently we have been taught that we can also make object directly, which I guess should go like

1
2
Animal animal(parameters);
animal.SetPosition(50,100); //or something like that 


however when I try this C++ just doesn't give any intellisense and I can't find any functions of the animal class...
While it does work with just using

1
2
Animal* animalPtr = new Animal(params);
animalPtr->SetPosition(50,100);


1) So have I done anything wrong? How should I correctly make an object without using pointers?

2) When creating an object as datamember, is that object then created in stack or heap?

3) Also, Heap memory only gets used for objects created with the new statement, right? So in theory all datamembers are stack?

Need help asap! exams 14th of june :P
Thx alot!
Last edited on
1) No, this is correct. Probably a bug with your IDE, try using one with better code completion.
2) That depends on where the containing object is located. If it's on the heap, then that's where its members are too.
3) See 2).
closed account (zwA4jE8b)
are you using VS2010?

looks like that code should work
Last edited on
4) So when stating
1
2
Animal* animalPtr = new Animal(params);
animalPtr->SetPosition(50,100);

the datamembers of the object are stored in the heap?

5) However when stating
Animal m_Animal;
as datamember in the header file of your program
then it is stored in stack I suppose?



@CreativeMFS Yes I'm using VS2010, however I just found out that it is the engine we're using causing the trouble. It doesn't allow to create certain objects in the stack...
Last edited on
Intellisense can be a bit odd at times, sometimes you have to wait for it to say "Hold on, um..............ok, back." as it rechecks your code. Creating class instances on the stack should be fine, intellisense just happened to zone out when you tried it. using the Rebuild Solution menu command should fix intellisense in most cases. You can also try closing the project and deleting the .ncb file (intellisense database) and then have it regenerate it correctly.
Last edited on
Topic archived. No new replies allowed.