eroare compilare

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
viorel2005
Membru
Membru
Posts: 208
Joined: 24 May 2008, 09:41

eroare compilare

Post by viorel2005 » 16 Jan 2013, 14:20

Salut!

Am urmatoarea eroare:
leftwnd.h(16) : error C2143: syntax error : missing ';' before '<class-head>'
Clasele au urmatorul cod:

Fisierul LeftWnd.h

Code: Select all

// LeftWnd.h: interface for the CLeftWnd class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_LEFTWND_H__14300435_7E38_4B40_A9F9_893BEF5C22AC__INCLUDED_)
#define AFX_LEFTWND_H__14300435_7E38_4B40_A9F9_893BEF5C22AC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

 
#include "RightWnd.h"

class CLeftWnd  
{
	
public:
	
	CLeftWnd(GtkWidget* parent)
		:myParent(parent)
		,myRightWnd(new CRightWnd(parent))
	{		
		myTarget = ::gtk_vbox_new(TRUE, 5);
		::gtk_paned_add1(GTK_PANED(myParent),myTarget);
	}
	
	void AddButton(const std::string& text, const std::string& button_id)
	{
		GtkWidget* button = ::gtk_button_new_with_label(text.c_str());
		::gtk_widget_set_name(button,button_id.c_str());
		;;gtk_widget_set_size_request(button,30,100);
		::g_signal_connect(G_OBJECT(button), "clicked",   G_CALLBACK(OnButtonClick), this);
		::gtk_box_pack_start(GTK_BOX(myTarget), button, true, true, 0);
	}

	
	GtkWidget* GetTarget() {	return myTarget;			}

	static void OnButtonClick(GtkWidget *widget, CLeftWnd* leftWnd);
	CRightWnd* GetRightWnd()	{	return myRightWnd;		}
private:
	GtkWidget* myParent;
	GtkWidget* myTarget;
	CRightWnd* myRightWnd;
	
};

#endif // !defined(AFX_LEFTWND_H__14300435_7E38_4B40_A9F9_893BEF5C22AC__INCLUDED_)

Fisierul LefWnd.cpp

Code: Select all

// LeftWnd.cpp: implementation of the CLeftWnd class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "LeftWnd.h"


void CLeftWnd::OnButtonClick(GtkWidget *widget, CLeftWnd* leftWnd)
{

	int x =atoi(::gtk_widget_get_name(widget));

	printf("Widget name is: %s and data = %d\n", ::gtk_widget_get_name(widget),x);
		
	if(x==1)
	{
		leftWnd->GetRightWnd()->Reset();
		leftWnd->GetRightWnd()->AddLine("Text 1", "text2", CRightWnd::CLineField::EDIT_CONTROL,"", "button 1", "button 2"); 
		leftWnd->GetRightWnd()->AddLine("Text 1", "text2", CRightWnd::CLineField::EDIT_CONTROL,"", "button 1", "button 2"); 
		
	}
	else if(x==2)
	{
		leftWnd->GetRightWnd()->Reset();
		leftWnd->GetRightWnd()->AddLine("Text 1", "text2", CRightWnd::CLineField::EDIT_CONTROL,"", "button 1", "button 2"); 
		leftWnd->GetRightWnd()->AddLine("Text 1", "text2", CRightWnd::CLineField::COMBO_CONTROL,"", "button 1", "button 2"); 
		leftWnd->GetRightWnd()->AddLine("Text 1", "text2", CRightWnd::CLineField::CHECK_CONTROL,"", "button 1", "button 2"); 
	}


}
Cum scap de ea?

Multumesc mult,
Viorel



User avatar
zlatomir
Membru++
Membru++
Posts: 282
Joined: 04 Jul 2009, 23:59
Location: Arad
Contact:

Re: eroare compilare

Post by zlatomir » 16 Jan 2013, 15:44

Uita-te in fisierul RightWnd.h ca cel mai probabil acolo ai o clasa la care ai uitat sa pui ; dupa acolada care inchide declaratia clasei.

viorel2005
Membru
Membru
Posts: 208
Joined: 24 May 2008, 09:41

Re: eroare compilare

Post by viorel2005 » 16 Jan 2013, 16:40

Am rezolvat. Multumesc pentru sfat. Era din cauza unui caracter in clasa CRightWind, dupa terminarea delclararii clasei.

User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: eroare compilare

Post by Marius Bancila » 16 Jan 2013, 23:48

Adica iti lipsea punct-si-virgula. Mda, am trecut toti prin asta, si o sa mai trecem, stai linistit. ;)
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

viorel2005
Membru
Membru
Posts: 208
Joined: 24 May 2008, 09:41

Re: eroare compilare

Post by viorel2005 » 17 Jan 2013, 10:14

Nu. Situatia era alta.

Fisierul A.h include fisierul B.h.
In fisirul B.h dupa #endif sau inainte, era caracterul g tastat din greseala.

Code: Select all

//B.h
class CB{
......
};

g
Cam asta era eroarea. Mie nu imi spunea ca eroarea este in fisierul B.h si ca este in fisierul A.h
Intrebarea este: cum as putea sa fac sa imi spuna ca eroare este in A.h.

Daca ai o clasa CA definita in A.h si ai o functie inline implementata in A.h care foloseste o metoda a clasei CB,
atunci nu poti avea in A.h ceva de genul:

Code: Select all

class CB;

class CA
{
public:
CA();
virtual ~CA();
inline void Apel(const CB& cb)
{
   cb.CallMe();
}
};


User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: eroare compilare

Post by Ovidiu Cucu » 17 Jan 2013, 23:31

Viorel, compilatorul nu-i altceva decat un program "prost, logic si cinstit".
Mai ales cinstit. ;)

User avatar
bu7ch3r
Membru++
Membru++
Posts: 326
Joined: 17 May 2011, 15:17
Judet: Iaşi
Location: Sofia
Contact:

Re: eroare compilare

Post by bu7ch3r » 18 Jan 2013, 10:04

Nu poti sa faci CB SI CA surori?
Cu stima,
Lupu Claudiu

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: eroare compilare

Post by Ovidiu Cucu » 18 Jan 2013, 10:56

viorel2005 wrote: Daca ai o clasa CA definita in A.h si ai o functie inline implementata in A.h care foloseste o metoda a clasei CB,
atunci nu poti avea in A.h ceva de genul:

Code: Select all

class CB;

class CA
{
public:
CA();
virtual ~CA();
inline void Apel(const CB& cb)
{
   cb.CallMe();
}
};

De putut, poti avea insa compilatorul, asa cum am mai spus e "cinstit" si-ti va da eroare.
De ce? Pentru ca in punctul in care apelezi CB::CallMe, el vede o declaratie a clasei CB, nu si definitia sa. Cu alte cuvinte, stie ca CB exista insa nu stie ce contine, inclusiv nu stie daca are sau nu metoda CallMe.
In alte limbaje o fi altfel, dar in C++ asta e! Compilatorul e destul de "prost" incat nu poate sa ghiceasca chestii pe care tu nu i le arati.
E "logic", nu-i asa? ;)

User avatar
bu7ch3r
Membru++
Membru++
Posts: 326
Joined: 17 May 2011, 15:17
Judet: Iaşi
Location: Sofia
Contact:

Re: eroare compilare

Post by bu7ch3r » 18 Jan 2013, 14:27

Eu intrebam daca poti sa faci asa ? :D

Code: Select all

#include "stdio.h"
class Base
{
public:
   virtual void Apel() = 0;
   virtual void CallMe()=0;
};

class CB : virtual public Base
{
    void CallMe(void)
    {
        //hahaha
        printf("VI works, cross delegation wors, VT is also merged");
    }
};

class CA : virtual public Base
{
public:
    virtual ~CA()
    {
    };
    void Apel()
    {
       CallMe();
    }
};

class CMyProblemSolved : public CA, public CB
{

};

int main (void)
{
    CMyProblemSolved POC;
    POC.Apel();
    return 1;
}
LATER EDIT:
Dar omul si-a rezolvat problema dar a dat ca rezolvare ceva ce nu linkeaza. Oricum ce-am scris am scris :)
Cu stima,
Lupu Claudiu

Post Reply