[Win32/c++] Operatoren

Pagina: 1
Acties:

  • Krooswijk.com
  • Registratie: Mei 2000
  • Laatst online: 17-08-2024
Hoi ik krijg vreemde foutmeldingen in mijn code. Ik heb een standaard control, waar andere zelf te maken controls van afgeleid kunnen worden.
De klasse heet BASIC_CONTROL

in de .h file heb ik ze als volgt gedeclareerd:
C++:
1
2
3
4
public:
friend bool operator == ( const BASIC_CONTROL& a, const BASIC_CONTROL& b );
friend bool operator != ( const BASIC_CONTROL& a, const BASIC_CONTROL& b );
BASIC_CONTROL& operator = ( const BASIC_CONTROL& a );


in m'n .cpp file include ik de .h file uiteraard en worden ze als volgt geimplementeerd:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
bool operator == ( const BASIC_CONTROL& a, const BASIC_CONTROL& b )
{
    if ( ( a.hwnd == b.hwnd ) &&        // Compare the window handle
     ( a.hinst == b.hinst ) &&      // Compare the instance handle
     ( a.name == b.name ) &&        // Compare the name
     ( a.winproc == b.winproc ) &&  // Compare the window proc
     ( a.x == b.x ) &&          // Compare the x coordinate
     ( a.y == b.y ) &&          // Compare the y coordinate
     ( a.width == b.width ) &&      // Compare the width
     ( a.height == b.height ) )     // Compare the height
    {
        return true;        // Two identical controls
    }
    else
    {
        return false;       // Control a and b differ
    }
}

bool operator != ( const BASIC_CONTROL& a, const BASIC_CONTROL& b )
{
    return !( a == b );         // Return !( a == b )
}

BASIC_CONTROL& BASIC_CONTROL :: operator = ( const BASIC_CONTROL& a )
{
    this->hwnd = a.hwnd;        // Assign the window handle
    this->hinst = a.hinst;      // Assign the instance handle
    this->name = a.name;        // Assign the name
    this->winproc = a.winproc;      // Assign the window proc
    this->x = a.x;          // Assign the x coordinate
    this->y = a.y;          // Assign the y coordinate
    this->width = a.width;      // Assign the width
    this->height = a.height;        // Assign the height

    return *this;           // Assign it to the operand
    }


in de .cpp file krijg ik echter de volgende foutmeldingen:

C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
regel 2:
Warning : function has no prototype

regel 3 t/m 10:
Error   : illegal access from 'BASIC_CONTROL' to protected/private member 'BASIC_CONTROL::hwnd'

regel 21:
Warning : function has no prototype
BASIC_CONTROL.cpp line 71    {

regel 22:
Error   : function call 'operator ==({lval} const BASIC_CONTROL, {lval} const BASIC_CONTROL)' is ambiguous
'PMI::operator ==(const BASIC_CONTROL &, const BASIC_CONTROL &)'
'operator ==(const BASIC_CONTROL &, const BASIC_CONTROL &)'
BASIC_CONTROL.cpp line 72     return !( a == b );     // Return !( a == b )


ik heb al van alles uitgeprobeerd, maar echt gericht zoeken kon ik niet, aangezien dit binnen mijn kennisgebied gewoon zou moeten werken, iemand enig idee wat er mis zou kunnen zijn. bvd.

[ Voor 6% gewijzigd door Krooswijk.com op 22-05-2003 13:59 ]


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 22-08 13:19

.oisyn

Moderator Devschuur®

Demotivational Speaker

Wat is WIN_CONTROL? Kun je de code eens posten van beide class definities?

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Krooswijk.com
  • Registratie: Mei 2000
  • Laatst online: 17-08-2024
heb het effe aangepast, win control bestaat niet en moet gewoon basic control zijn...
was een foutje bij het posten, probleem hetzelfde dus nog...

classe definitie van BASIC_CONTROL:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef BASIC_CONTROL_H
#define BASIC_CONTROL_H

#if PRAGMA_ONCE
#pragma once
#endif

#include <windows.h>
#include <string>

class BASIC_CONTROL
{

    private:

        BASIC_CONTROL( );

    protected:

        HWND        hwnd;           // window handle
        HINSTANCE   hinst;          // instance handle
        string      name;           // name
        WNDPROC     winproc;        // winproc
        int         x,              // x coordinate
                    y,              // y coordinate
                    width,          // window width
                    height;         // window height
        DWORD       style_flags;    // window style flags

    public:

        friend bool operator == ( const BASIC_CONTROL& a, const BASIC_CONTROL& b );
        friend bool operator != ( const BASIC_CONTROL& a, const BASIC_CONTROL& b );
        BASIC_CONTROL& operator = ( const BASIC_CONTROL& a );

        BASIC_CONTROL(  const HWND      window_handle,
                        const HINSTANCE instance_handle,
                        const string    control_name,
                        const WNDPROC   win_proc_defined,
                        const int       x,
                        const int       y,
                        const int       width,
                        const int       height,
                        const DWORD     style_flags = NULL );

        ~BASIC_CONTROL( );

//      ... allerlei functies...

        int register_me( void *my_control );
};

#endif

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 22-08 13:19

.oisyn

Moderator Devschuur®

Demotivational Speaker

Die string moet trouwens std::string zijn, maar afgezien van dat compileert het hier prima

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Krooswijk.com
  • Registratie: Mei 2000
  • Laatst online: 17-08-2024
oh ja der hoort inderdaad nog een "using namespace std" bij :)
bij een collega van me compileert ie ook goed...

ik ga eens even wat instellingen nalopen

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 22-08 13:19

.oisyn

Moderator Devschuur®

Demotivational Speaker

een using namespace declaratie is uit den boze in een header file... schrijf gewoon de volledige namen (dus std::*), ze staan niet voor niets in een eigen namespace

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 21-08 17:14
De laatste error laat zien wat er fout gaat:
Ambiguous:
'PMI::operator ==(const BASIC_CONTROL &, const BASIC_CONTROL &)'
'operator ==(const BASIC_CONTROL &, const BASIC_CONTROL &)'
Er zijn dus twee operator==s, een binnen namespace PMI en een daarbuiten. De ene is friend declaratie, de andere de functie definitie. De gedefinieerde operator== is dus geen friend!

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein

Pagina: 1