Hello, I have tried to create a new class and implement it as a cpp file and a header. All of my attempts at using the tutorials yield the same problem, I get a load of syntax errors. I've tried deleting the class and using the IDE's create a new class function as well with no avail. My source code runs fine without the classes and doesn't reference the class at all.
Header File:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#pragma once
class CodexData
{
public:
string *getKnownWords();
int *getTopicCodes();
string getData(int code);
CodexData(string book);
~CodexData();
private:
string *words;
int *topic_codes;
bool setWords(string book);
void resize(int size);
void error(string message);
string intToString(int i);
};
Error 1 error C2143: syntax error : missing ';' before '*' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 6 1 KarLaiProject
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 6 1 KarLaiProject
Warning 3 warning C4183: 'getKnownWords': missing return type; assumed to be a member function returning 'int' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 6 1 KarLaiProject
Error 4 error C2146: syntax error : missing ';' before identifier 'getData' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 8 1 KarLaiProject
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 8 1 KarLaiProject
Warning 6 warning C4183: 'getData': missing return type; assumed to be a member function returning 'int' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 8 1 KarLaiProject
Error 7 error C2061: syntax error : identifier 'string' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 9 1 KarLaiProject
Error 8 error C2143: syntax error : missing ';' before '*' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 12 1 KarLaiProject
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 12 1 KarLaiProject
Error 10 error C2061: syntax error : identifier 'string' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 14 1 KarLaiProject
Error 11 error C2061: syntax error : identifier 'string' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 16 1 KarLaiProject
Error 12 error C2146: syntax error : missing ';' before identifier 'intToString' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 17 1 KarLaiProject
Error 13 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 17 1 KarLaiProject
Warning 14 warning C4183: 'intToString': missing return type; assumed to be a member function returning 'int' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.h 17 1 KarLaiProject
Error 15 error C2511: 'CodexData::CodexData(std::string)' : overloaded member function not found in 'CodexData' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 9 1 KarLaiProject
Error 16 error C2660: 'CodexData::setWords' : function does not take 1 arguments c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 10 1 KarLaiProject
Error 17 error C2511: 'bool CodexData::setWords(std::string)' : overloaded member function not found in 'CodexData' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 43 1 KarLaiProject
Error 18 error C2660: 'CodexData::error' : function does not take 1 arguments c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 47 1 KarLaiProject
Error 19 error C2065: 'words' : undeclared identifier c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 53 1 KarLaiProject
Error 20 error C2597: illegal reference to non-static member 'CodexData::topic_codes' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 62 1 KarLaiProject
Error 21 error C3867: 'CodexData::topic_codes': function call missing argument list; use '&CodexData::topic_codes' to create a pointer to member c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 62 1 KarLaiProject
Error 22 error C2109: subscript requires array or pointer type c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 62 1 KarLaiProject
Error 23 error C2065: 'words' : undeclared identifier c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 63 1 KarLaiProject
Error 24 error C2352: 'CodexData::intToString' : illegal call of non-static member function c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 68 1 KarLaiProject
Error 25 error C2660: 'CodexData::error' : function does not take 1 arguments c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 68 1 KarLaiProject
Error 26 error C2556: 'std::string CodexData::intToString(int)' : overloaded function differs only by return type from 'int CodexData::intToString(int)' c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 77 1 KarLaiProject
Error 27 error C2371: 'CodexData::intToString' : redefinition; different basic types c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 77 1 KarLaiProject
Warning 28 warning C4244: '=' : conversion from 'double' to 'char', possible loss of data c:\users\louis\documents\visual studio 2013\projects\karlaiproject\karlaiproject\codexdata.cpp 90 1 KarLaiProject
Just going to point out that you need to write #include <string> in the header file, but don't write using namespace std; in the header file, just use std::string instead of string.
Some of the functions in the cpp file are defined as regular functions and not member functions.
I am not sure why you put the function declarations for setWords() resize() and error() in private. They would work better in public or you would need public functions to access the private functions.
Sorry for the late reply, for the private functions, they are just used by the public functions so I didn't think they'd need to be accessed outside the class. Could that be the reason for the errors? Thanks krako, I'll try that and get back to you.
#pragma once
#include <string>
class CodexData
{
public:
string *getKnownWords(); // Returns the known words list which is parallel to the topic codes array.
int *getTopicCodes(); // Returns the topic codes array.
string getData(int code); // Search the file for data on that topic number and return it.
CodexData(string book); // Open the file specified ready for reading.
~CodexData(); // Free up the memory used by dynamic arrays.
private:
string *words;
int *topic_codes; // Parallel arrays containing the topic code incrementer e.g words[1] = "for" topic_codes[1] = 2; for loops in java might be topic code + 20 for java. 22.
bool setWords(string book); // Sets the words and also the topic codes for that word.
void resize(int size); // Resizes the dynamic arrays.
void error(string message);
string intToString(int i);
};