Home > error c2514 > error c2514 forward declaration

Error C2514 Forward Declaration

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack class has no constructors c++ Overflow the company Business Learn more about hiring developers or posting ads with us

Incomplete Type Is Not Allowed

Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error C2514 class has no constructors. But it does? up vote 1 down vote favorite I'm getting: Error 1 error C2514: 'EmployeeListNode' : class has no constructors in ListOfEmployee.cpp But in EmployeeListNode.h I have: class EmployeeListNode { friend class ListOfEmployee; public: EmployeeListNode(string name, double salary); //A constructor no? }; I don't understand why it won't recognise that as a constructor. Sorry if this is a stupid question, but I couldn't find an answer through searching. Edit: The section of the ListOfEmployee that's giving the errors: void ListOfEmployee::insert(string nameIn, double salaryIn){ EmployeeListNode *n1 = new EmployeeListNode(nameIn, salaryIn); EmployeeListNode* tn; if (head){ head = n1; }else{ for (tn = head; tn->next; tn = tn->next); } } Edit 2: And the ListOfEmployee.h in case it makes a difference: #pragma once #include using namespace std; class EmployeeListNode; class ListOfEmployee { public: ListOfEmployee(); void insert(string name, double salary); void display(); void deleteMostRecent(); double getSalary(string name); ~ListOfEmployee(); private: EmployeeListNode *head; }; c++ share|improve this question edited Nov 20 '15 at 10:37 asked Nov 20 '15 at 10:28 Shannon Birch 337 Looks like you're trying to default-construct an EmployeeListNode somewhere. Maybe you have one as a class member and don't initialize it in the initialization list? Please post where the error comes from. –TartanLlama Nov 20 '15 at 10:32 I edited it to add the section of ListOfEmployee.cpp that is giving the error. –Shannon Birch Nov 20 '15 at 10:34 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted It can be that you only forward-declared ListOfEmployeeNode, without including it's header (and therefore definition) where it is used. In that case, the compiler knows about the class, but cannot access any members, including constructors. If you did include the header, check your i

Forum Visual C++ & C++ Programming C++ (Non Visual C++ Issues) class has no constructors possible forward class declaration error HELP! If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register or Login before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 14 of 14 Thread: class has no constructors possible forward class declaration error HELP! Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid http://stackoverflow.com/questions/33824338/error-c2514-class-has-no-constructors-but-it-does Mode Switch to Threaded Mode July 4th, 2008,07:41 PM #1 TyTheProgrammer89 View Profile View Forum Posts Junior Member Join Date Jul 2008 Posts 4 class has no constructors possible forward class declaration error HELP! Hello everyone, this is my first forum post here so I don't really know what to say but anyways here it goes! I'm having a problem with my Iterator Assignment. What the teacher wants us to do is a terrible example http://forums.codeguru.com/showthread.php?456597-class-has-no-constructors-possible-forward-class-declaration-error-HELP! of an actual Iterator but he said we'll be working with it more next week he just wants us to get the general idea. Anyways here's the error I get... error C2514: 'StackIterator' : class has no constructors I guess the error is there because the StackIterator constructor does not recognize 'this' as a Stack pointer in the parameters of the createIterator function. Thanks in advance! stack.h Code: #ifndef STACK_H #define STACK_H class StackIterator; class Stack { public: Stack( void ); ~Stack( void ); bool Push( int ); int Pop( void ); StackIterator* createIterator() const; int m_Items[10]; private: int m_Total; }; StackIterator* Stack::createIterator() const { // ********* ERROR ************ return new StackIterator( this ); } #endif Code: #include "stdafx.h" #include "Stack.h" Stack::Stack( void ) : m_Total( -1 ) { for( int i = 0; i < 10; i++ ) { m_Items[i] = 0; } } Stack::~Stack( ) { } bool Stack::Push( int value ) { m_Total++; if( m_Total == 10 ) return false; m_Items[m_Total] = value; return true; } int Stack::Pop( void ) { int value; if( m_Total <= 0 ) return -1; value = m_Items[m_Total]; m_Total--; return value; } Code: #ifndef STACKITERATOR_H #define STACKITERATOR_H #include "Stack.h" class StackIterator { public: StackIterator( Stack* ); ~StackIterator( void ); void First( void ); void Next( void ); int GetData( void ); bool Complete( voi

equation class to be solved. // https://www.daniweb.com/programming/software-development/threads/375564/forward-declaration-wrong #ifndef DIFFUSIONTERM_H #define DIFFUSIONTERM_H #include #include using namespace std; class Equation; class DiffusionTerm { private: Equation* pEquation; public: DiffusionTerm(Equation* _pEquation http://www.thecodingforums.com/threads/class-has-no-constructors.678959/ ){pEquation=_pEquation; }; ~DiffusionTerm(){}; vectorCoe; vectorsource; void evaluateCoeAndSource( ) { vector& ThermalConductivity= pEquation->pMedia->getThermalConductivity() ; } }; // // Equation.h define the error c2514 equation class to be solved. // #ifndef EQUATION_H #define EQUATION_H #include "Mesh.h" #include"Variable.h" #include"Media.h" #include"Simulation.h" #include #include #include #include #include using namespace std; class DiffusionTerm; class Equation { protected: // the equation name it should be error c2514 forward the same with the variaible name string name; // the equation residual double residual; // a pointer to the Mesh Mesh* pMesh; // a pointer to the varible soved in the equation Variable* pVariable; // a pointer to the simulation Simulation* pSimulation; DiffusionTerm* pDiffusionTerm; // a pointer to the media Media* pMedia; // the matrix A that contain the discretised equation Ax=source vector csrA; // the source contain the discretised equation source term vector source; map> boundaryNameAndVectorMap; public: // the default constructor with no parameter Equation() { pVariable=new Variable(); pDiffusionTerm=new DiffusionTerm(this); int size=pMesh->getNbCells(); pVariable->setSize(size); source.resize(size); csrA.resize(pMesh->getNbNoneZero() ); } // the constructor with one parameter name Equation(const string& aName) { name=aName; pVariable=new Variable();int size=pMesh->getNbCells(); pVariable->setSize(size);source.resize(size); csrA.resize(pMesh->getNbNoneZero() );} ~Equation(){pVariable->cle

error C2514: 'GlyphTexCoords' : class has no constructors /* Forward declarations */ struct Vector2f; struct GlyphPosition; struct GlyphTexCoords; struct GlyphColors; ///////////////////////////////////////////////////////////////////// // class OpenGLFont // class OpenGLFont { public: vector TextureCoordinates; void SetFont(CFont font) { ... float uStart = x / fSquareDim; float uEnd = (x + CharacterWidths) / fSquareDim; float vEnd = (y + myHeight) / fSquareDim; TextureCoordinates = GlyphTexCoords(uStart, vStart, uEnd, vEnd); } }; //OpenGLFont struct GlyphTexCoords { Vector2f BottomLeft; Vector2f TopLeft; Vector2f BottomRight; Vector2f TopRight; GlyphTexCoords() {} GlyphTexCoords(float left, float top, float right, float bottom) { TopLeft.X = BottomLeft.X = left; TopLeft.Y = TopRight.Y = top; TopRight.X = BottomRight.X = right; BottomLeft.Y = BottomRight.Y = bottom; } }; Don't understand becaue there is a constructor... Vincent R, Apr 7, 2009 #1 Advertisements Victor Bazarov Guest Vincent R wrote: > When trying to compile the following code I get an error with MS > compiler error C2514: 'GlyphTexCoords' : class has no constructors > > > > /* Forward declarations */ > struct Vector2f; > struct GlyphPosition; > struct GlyphTexCoords; Here you declare that 'GlyphTexCoords' is some kind of a class. > struct GlyphColors; > > ///////////////////////////////////////////////////////////////////// > // class OpenGLFont > // > class OpenGLFont > { > public: > vector TextureCoordinates; I am not sure this is actually legal. A template argument cannot be an incomplete type, IIRC. If VC++ allows you to get away with that, that's fine, but expect portability issues. > > void SetFont(CFont font) > { > > ... > > float uStart = x / fSquareDim; > float uEnd = (x + CharacterWidths) / fSquareDim; > float vEnd = (y + myHeight) / fSquareDim; > > TextureCoordinates = GlyphTexCoords(uStart, vStart, uEnd, vEnd); Compiling this function requires to know what 'GlyphTexCoords' constructor to call on that line. Since the class 'GlyphTexCoords' has not yet been defined here (it is defined below), the compiler is unable to compile that assignment statement. Take the entire function 'SetFont' and define it in a translation unit, as all normal code should be. Or move the definition of the 'GlyphTexCoords' class above the definition of 'OpenGLFont'. > > } > }; //OpenGLFont > > struct GlyphTexCoords > { > Vector2f BottomLeft; > Vecto

 

Related content

error c2514

Error C table id toc tbody tr td div id toctitle Contents div ul li a href Incomplete Type Is Not Allowed a li ul td tr tbody table p resources Windows Server resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student relatedl Partners ISV Startups TechRewards Events Community Magazine Forums c forward declaration class has no constructors Blogs Channel Documentation APIs and reference Dev centers Retired p h id Incomplete Type Is Not Allowed p content Samples We re sorry The content you requested has been removed You ll be auto redirected in second C C