I'm working with VS 2010's C++. Been a VB guru for far too long and trying to transfer my skills to the C++ world. Anyway, with that said, I'm very familiar with classes, but finding it difficult to implement a simple class on C++. So heres what I got. I got a simple Vector class in a header file:
//Vector.h
#ifndef VECTOR_TEST
#define VECTOR_TEST
class Vector
{
public:
float x,y;
}
#endif VECTOR_TEST
And when I tried declaring it, and displaying the result in a Messagebox, I got a lot of error messages. Most of which has nothing to do with me making an error in my code:
//Main.cpp
#include "Vector.h"
#include <stdio.h>
#include <Windows.h>
int main(void)
{
Vector* v = new Vector[2];
v[0].x = 5;
char Text[255];
sprintf(Text,"%f", v[0].x);
MessageBox(NULL, Text, "typedef", MB_OK);
return 0;
}
And these are the errors I received:
1>------ Build started: Project: Header Test, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Vector' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Vector' followed by 'int' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2347: '__w64' : can not be used with type '__w64 Vector'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2371: 'size_t' : redefinition; different basic types
1> c:\c++ self tutorial\header test\header test\predefined c++ types (compiler internal)(19) : see declaration of 'size_t'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
These errors seem to be all based on sourceannotations.h. I never really included this header at all and have no idea why its even being brought up. I only got 2 measly files. Main.cpp and Vector.h. Now if I don't use the Vector.h header and simply just do this:
#include <stdio.h>
#include <windows.h>
Integer main(void)
{
charText[255];
int Number = 5;
sprintf(Text,"%i", Number);
MessageBox(NULL, Text, "Message", MB_OK);
return 0;
}
Then it works just fine, like its nothing. Could anyone help me get a simple class going from the Vector header and tell me whats wrong? Thanks in advance.