I'm writing a singly linked list class and I have just started. I'm having problems withHere is my code:Code:(*startPointer).name = name;
main.cpp
LinkedList.cppCode:#include <iostream> #include <cstring> #include "LinkedList.h" using namespace std; int main() { cout << "Enter your name:" << endl; char myName[20]; cin.getline(myName, 20, '\n'); return 0; }
LinkedList.hCode:#include <cstdlib> #include <iostream> #include <cstring> #include "../include/LinkedList.h" //default constructor LinkedList::LinkedList() : startPointer(NULL), length(0) { } //destructor LinkedList::~LinkedList() { } bool LinkedList::createNode(char name[]) { if(startPointer == NULL) { startPointer = new aNode;//aNode is a struct (*startPointer).name = name; std::cout << "Should be the same: " << (*startPointer).name <<std::endl; } return true; }
In constructor 'LinkedList::LinkedList()':Code:#ifndef LINKEDLIST_H #define LINKEDLIST_H class LinkedList { public: LinkedList(); ~LinkedList(); void addToList(); bool createNode(char name[]); private: unsigned int length; struct aNode { char name[20]; aNode *next; }; aNode *startPointer; }; #endif // LINKEDLIST_H
warning: 'LinkedList::startPointer' will be initialized after
warning: 'unsigned int LinkedList::length'
warning: when initialized here
In member function 'bool LinkedList::createNode(char*)':
error: incompatible types in assignment of 'char*' to 'char [20]'
warning: no return statement in function returning non-void



LinkBack URL
About LinkBacks



