Here is my code, not working =(
FILE: main.cpp:
1 2 3 4 5 6 7 8 9
|
#include "cscd305_w12_lab3.h"
int main()
{
CArray integers1(7); // seven-element CArray
CArray integers2; // 10-element CArray by default
// print integers1 size and contents
cout << "Size of CArray integers1 is " << integers1.getSize() << endl;
|
FILE: cscd305_"w12_lab3.h"
1 2 3 4 5 6 7
|
#pragma once
#include "CArray.h";
#include <iostream>
#include <string>
using namespace std;
|
FILE: CArray.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include "cscd305_w12_lab3.h"
CArray::CArray()
{this->m_array = new int[10];}
CArray::CArray(int size)
{this->m_array = new int[size];}
CArray::~CArray(void)
{delete[] this->m_array;}
int getSize(void)
{(sizeof this->m_array) / sizeof(int);}
|
FILE: CArray.h
1 2 3 4 5 6 7 8 9 10 11 12
|
class CArray
{
public:
CArray();
CArray(int size);
~CArray();
int getSize();
private:
int *m_array;
};
|
Errors:
Error 2 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.h 2 error C2011: 'CArray' : 'class' type redefinition
Error 3 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 4 error C2027: use of undefined type 'CArray'
Error 7 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 9 error C2027: use of undefined type 'CArray'
Error 11 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 14 error C2027: use of undefined type 'CArray'
Error 4 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 4 error C2059: syntax error : ')'
Error 8 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 9 error C2062: type 'int' unexpected
Error 12 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 14 error C2062: type 'void' unexpected
Error 5 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 5 error C2143: syntax error : missing ';' before '{'
Error 9 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 10 error C2143: syntax error : missing ';' before '{'
Error 13 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 15 error C2143: syntax error : missing ';' before '{'
Error 6 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 5 error C2447: '{' : missing function header (old-style formal list?)
Error 10 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 10 error C2447: '{' : missing function header (old-style formal list?)
Error 14 c:\users\josh\documents\visual studio 2010\projects\cscd305\lab 3\carray.cpp 15 error C2447: '{' : missing function header (old-style formal list?)