Page 1 of 4

Confusion

Posted: Fri Jan 21, 2011 8:53 pm
by THe Floating Brain
Well lately I have been developing a game engine that contains the following class.

Code: Select all

class MiscFucntions
{
public:
	class InstanceCreate
	{
		public:
			typedef class Instance;
			typedef std::vetcor<Instance> Vetcor;
			template<class Instance>
			Instance CreateInstance(Instance A)
			{
				
				return A;
			}
			
	};
	class InstanceDestroy
	{
	public:
		//Not done!!//
		typedef class InstanceToDestroy;
		template<class InstanceToDestroy>
		InstanceToDestroy DestroyInstance(InstanceToDestroy ClassInstanceToDestroy)
		{
		}
	};

};
The way I have used this function "CreateInstance" is the following...

Code: Select all

//"fedship" is a class an "fedships" is a std::vetcor.//
		MiscFucntions::InstanceCreate V;
		fedship A;
		fedship B;
		*fwrexp = 300;
		*fwreyp = 300;
		fedships.push_back(V.CreateInstance(A));
		*fwreyp += 100;
		fedships[0] = B.SetPosition(*fwrexp, *fwreyp, fedships[0]);
		fedships.push_back(V.CreateInstance(A));
//etc...///
If I create five "fedships" in the std::vector "fedships" this is my console output
OMG.PNG
OMG.PNG (35.59 KiB) Viewed 2192 times
(Hoping the messages are relatively understandable).
I have noticed every frame that "fedships" subtracts a "fedship" (35 on the first frame :/) but yet all instances of "fedship" remain functional and :/ Also I cannot modify "fedships" for example the "SetPosition" function that is up there does not work :-( .
I am getting the feeling that std::vectors are not the way to go for this and I was wondering if there was another type of container or something that would be like a std::vector but with no memory heap allocation? Also I was wondering (although not expecting) if anyone can understand the reason for this behavior in my program?
P.s I know I sometimes have a hard time getting my point across if anyone needs any clarification I will do my best to provide it.
P.s.s Sorry for making 2 posts in 1 week :-(
P.s.s.s Yes I know this is probably the most n00by pice of code your eyes have ever had to bear whitness to.
EDIT:
Also noticed after this post that another indicator in my log says that "fedships" is of the correct size 5.

Re: Confusion

Posted: Fri Jan 21, 2011 9:03 pm
by dandymcgee
I think you should seriously consider chilling out and letting your brain catch up to your ambition, at least until you read up on some fundamentals of C++.

First of all, you're not ready for templates. Perhaps not even pointers or classes. Check out the tutorials on this page from "Compound Data Types" forward:
http://www.cplusplus.com/doc/tutorial/

When you feel as though you thoroughly understand the concepts laid out there, then come back to play with the code you've posted.

Hope I did well not making this sound too harsh. 8-)

Re: Confusion

Posted: Fri Jan 21, 2011 9:11 pm
by THe Floating Brain
It is not that I do not understand them I fully understand them (well maybe not stl stuff) I have been programming/learning for almost 3 years now(last year of that being programming only). Most of the problem lies in the fact that my code is going from spaghetti code to engine and I am getting a lot of crap like this. Sooo I was kinda thinking if someone could help me with this maybe I could use there help to figure out future problems, plus it is kinda late were I am so I probably seem kinda stupid right now XD
----EDIT----
I will admit I proabably took ten minutes then was like "OMG I JUST WANT TO MOVE ON!!" and made this post.

Re: Confusion

Posted: Fri Jan 21, 2011 11:34 pm
by xiphirx

Code: Select all

         typedef std::vetcor<Instance> Vetcor;
Stopped reading there.

Re: Confusion

Posted: Fri Jan 21, 2011 11:41 pm
by THe Floating Brain
Oh wooops ment to get rid of that (not being used).

Re: Confusion

Posted: Sat Jan 22, 2011 2:44 am
by adikid89

Code: Select all

         typedef class Instance;   //wuuuuuut.......
         typedef std::vetcor<Instance> Vetcor;
         template<class Instance>   
weird?

Re: Confusion

Posted: Sat Jan 22, 2011 9:13 am
by THe Floating Brain
adikid89 wrote:

Code: Select all

 typedef class Instance; //wuuuuuut.......
typedef std::vetcor<Instance> Vetcor;
template<class Instance> 
weird?
The second line is suppost to be removed.

Re: Confusion

Posted: Sat Jan 22, 2011 11:40 am
by N64vSNES
adikid89 wrote:

Code: Select all

         typedef class Instance;   //wuuuuuut.......
         typedef std::vetcor<Instance> Vetcor;
         template<class Instance>   
weird?
+1

Does that honestly compile? :shock2:

Re: Confusion

Posted: Sat Jan 22, 2011 12:11 pm
by THe Floating Brain
VC++ 2008 FTW!! Howcome everyone keeps focusing on this one line?

Re: Confusion

Posted: Sat Jan 22, 2011 12:45 pm
by N64vSNES
THe Floating Brain wrote:VC++ 2008 FTW!! Howcome everyone keeps focusing on this one line?
I'm not looking at the second line its the first:-

Code: Select all

typedef class Instance; // <---- This one
typedef std::vetcor<Instance> Vetcor;
template<class Instance>   
typedef defines types, but a class isn't a type so you should get a error/warning.

Why would you you want this anyway? and whats wrong with

Code: Select all

#define Instance class

Re: Confusion

Posted: Sat Jan 22, 2011 7:32 pm
by THe Floating Brain
As dipicted in most tutorials that is valid C++ syntex, reason being I dont use

Code: Select all

#define Instance class
is this is simply the way I thought of doing that.

Re: Confusion

Posted: Sat Jan 22, 2011 9:56 pm
by Ginto8
... It still begs the question... WHY?

Re: Confusion

Posted: Sat Jan 22, 2011 10:02 pm
by xiphirx
Ginto8 wrote:... It still begs the question... WHY?
To make him write less... er

Re: Confusion

Posted: Sun Jan 23, 2011 1:07 am
by THe Floating Brain
Beacuse I did not want to deal with pre-prosser commands

Re: Confusion

Posted: Sun Jan 23, 2011 1:28 am
by xiphirx
THe Floating Brain wrote:Beacuse I did not want to deal with pre-prosser commands
wat

are you a troll by chance?