Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
14 / 14 / 4
Регистрация: 08.08.2010
Сообщений: 117
1

требала с екстерналами

14.03.2011, 10:05. Показов 400. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Всем не хворать! Пишу класс, чтото типа стринг.
хедер:
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
#pragma once
 
class Cue
{
    int size, step, curInd;
    char* Str;
    void newMem();
    void terminate();
public:
    Cue();
    ~Cue(void);
 
 
    Cue (char* pStr, int iSize);
    Cue (const Cue & right);
    
    Cue & operator =(const Cue & right);
    Cue & operator +(const Cue & right);
    Cue & operator +(const char * right);
    Cue & operator +(const char right);
    Cue & operator +=(const char right);
    Cue & operator +=(const Cue & right);
    Cue & operator +=(const char * right);
 
 
    void Out();
    void Input();
};
CPP:

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "stdAfx.h"
#include "Cue.h"
 
 
//void Cue::Func()
 
void Cue::terminate()
{
    Str[curInd] = 0;
}
 
Cue::Cue():size(5), step(2), curInd(0)
 
{
    //cout<<"Cue constr (int,int)"<<size<<" "<<this<<endl;
    if (size!=0)
    Str = new char [size];
}
Cue::Cue(char* RightStr, int iSize):size(iSize), step(iSize/2), curInd(0),
Str(new char [size])
{
    //cout<<"Cue constr (int,int)"<<size<<" "<<this<<endl;
    for (int i=0; i<size; ++i)
        Str += RightStr[i];
    terminate();
}
Cue::~Cue()
{
    //cout<<"Cue destr (int,int)"<<size<<" "<<this<<endl;
    /*if (size!=0)
    delete[] Str;*/
}
 
void Cue::newMem()
{
    char* iTemp=new char[size+step];
        strcpy_s(iTemp, sizeof(char)*(size+step), Str );
        strcpy_s(Str, sizeof(char)*(size+step), iTemp);
        //delete Str;
        //Str=iTemp;
        size+=step;
        step=size/2;
}
 
void Cue::Out()
{
    cout<<Str<<endl;
    
}
 
 
 
Cue::Cue(const Cue & right):size(right.size), step(right.step), curInd(right.curInd),
Str(new char [size])
{
    memcpy(Str, right.Str, sizeof(char)*size);
}
 
Cue & Cue::operator +(const char right)
{
    if (curInd==size)
    { 
        newMem();
    }
    
    Str[curInd++]=right;
    terminate();
    return *this;
 
}
 
Cue & Cue::operator +(const Cue & right)
{
    Cue temp(*this);
    for (int i = 0; i < right.size; ++i)
    {
        strcat(temp.Str, right.Str);
    }
    temp.size += right.size;
    temp.step += right.step;
    temp.curInd += right.curInd;
    
    return temp;
}
 
Cue & Cue::operator =(const Cue &right)
{
    if (this!=&right)
    {
        char *pBuf;
        pBuf = new char [sizeof(Cue)];
        //char *pBuf = new char [sizeof(Cue)];
        memcpy(pBuf, this, sizeof(Cue));
        Cue aTemp(right);
        memcpy(this, &aTemp, sizeof(Cue));
        memcpy(& aTemp, pBuf, sizeof(Cue));
        delete [] pBuf;
    }
    return *this;
}
 
 
 
 
void Cue::Input()
{
    char ch = 'h';
    while (ch!=13)
    {
        ch = _getch();
        cout<<ch;
        *this += ch;
    }
    cout<<endl;
}
 
 
Cue & Cue::operator +=(const char right)
{
    *this + right;
    return *this;
}
 
 
 
Cue & Cue::operator +=(const Cue & right)
{
    *this +right;
    return *this;
}
Cue & Cue::operator +=(const char * right)
 
{
    *this + right;
    return *this;
}
 
 
 
//Cue::
ошибка:
Error 3 error LNK2019: unresolved external symbol "public: class Cue & __thiscall Cue::operator+(char const *)" (??HCue@@QAEAAV0@PBD@Z) referenced in function "public: class Cue & __thiscall Cue::operator+=(char const *)" (??YCue@@QAEAAV0@PBD@Z) E:\VS Projects\blondie c++\blondie c++\Cue.obj blondie c++


Error 4 error LNK1120: 1 unresolved externals E:\VS Projects\blondie c++\Debug\blondie c++.exe 1 1 blondie c++


Помогите пожалуйста, буду очень благодарен!
0
126 / 126 / 42
Регистрация: 12.03.2011
Сообщений: 227
14.03.2011, 10:19 2
Видимо у вас не инициализирована
C++
1
Cue & operator +(const char * right);
0
6045 / 2160 / 753
Регистрация: 10.12.2010
Сообщений: 6,005
Записей в блоге: 3
14.03.2011, 10:22 3
В прототипе перегруженного оператора "+" (первый) в качестве второго формального операнда у вас фигурирует указатель, а в реализации - ссылка.
1
14.03.2011, 10:22
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru