Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 24.10.2015, 17:40   #1
Forsby
Новичок
Джуниор
 
Регистрация: 24.10.2015
Сообщений: 2
По умолчанию Помогите найти ошибку

Здравствуйте.
Суть вопроса: есть класс битового поля, компилятор выдаёт следующие ошибки:

Ошибка LNK1120 неразрешенных внешних элементов: 1 TBitField C:\Git Project\TBitField\Debug\TBitField.e xe 1

Ошибка LNK2019 ссылка на неразрешенный внешний символ "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class TBitField &)" (??6@YAAAV?$basic_ostream@DU?$char_ traits@D@std@@@std@@AAV01@AAVTBitFi eld@@@Z) в функции _main TBitField C:\Git Project\TBitField\TBitField\main.ob j 1

Код:
.h
Код:
#include<iostream> 
#include "stdafx.h" 
#pragma once 
using namespace std;
typedef unsigned int TELEM;
class TBitField
{
	int BitLen; //длина битового поля 
	int MemLen; //размер массива 
	TELEM *pMem;
	int GetMemIndex(const int n) const;
	TELEM GetMemMask(const int n) const; //битовая маска 
public:
	TBitField(int Len);
	TBitField(const TBitField &);
	~TBitField();
	int GetLenght(void) const ;
	void SetBit(const int n);
	void ClrBit(const int n);
	int GetBit(const int n) const;
	const TBitField& operator= (const TBitField&);
	TBitField operator |(const TBitField &); 
	TBitField operator &(const TBitField &);
	TBitField operator ~(void);
	bool operator== (const TBitField&);
	friend istream & operator>>(istream &/*istr*/, TBitField &);
	friend ostream & operator<<(ostream &/*ostr*/, TBitField &);
};
.cpp
Код:
#include "stdafx.h" 
#include "TBitField.h" 
#include<iostream> 
using namespace std;

int TBitField::GetMemIndex(const int n) const
{
	return n>>5;
}
TELEM TBitField::GetMemMask(const int n) const
{
	return 1 <<(n & 31);
}
TBitField::TBitField(int Len)
{
	BitLen = Len;
	MemLen = (Len + 31) >> 5;
	pMem = new TELEM[MemLen];
	if (pMem != NULL)
		for (int i = 0; i < MemLen; i++)
			pMem[i] = 0;
}
TBitField::TBitField(const TBitField & BF)
{
	BitLen = BF.BitLen;
	MemLen = BF.MemLen;
	pMem = new TELEM[MemLen];
	if (pMem != NULL)
		for (int i = 0; i < MemLen; i++)
			pMem[i] = BF.pMem[i];
}
TBitField::~TBitField()
{
	delete[]pMem;
}
int TBitField::GetLenght(void) const
{
	return BitLen;
}
void TBitField::SetBit(const int n)
{
	if ((n >= 0) && (n < BitLen))
		pMem[GetMemIndex(n)] |= GetMemMask(n);
}
void TBitField::ClrBit(const int n)
{
	if ((n >= 0) && (n < BitLen))
		pMem[GetMemIndex(n)] &= ~GetMemMask(n);
}
int TBitField::GetBit(const int n) const
{
	if ((n >= 0) && (n < BitLen))

		return pMem[GetMemIndex(n)] & GetMemMask(n);
	else return 0;
}
const TBitField& TBitField::operator= (const TBitField & BF) 
{
	BitLen = BF.BitLen;
	if (MemLen != BF.MemLen) {
		MemLen = BF.MemLen;
		if (pMem != NULL)
			delete[]pMem;
		pMem = new TELEM[MemLen];
	}
	for (int i = 0; i < MemLen; i++)
		pMem[i] = BF.pMem[i];
	return *this;
}
TBitField TBitField::operator&(const TBitField & BF)
{
	int MaxMemLen;
	if (MemLen > BF.MemLen)
		MaxMemLen = MemLen;
	else MaxMemLen = BF.MemLen;
	TBitField Res(MaxMemLen);
	for (int i = 0; i < MemLen; i++)
		Res.pMem[i] = pMem[i];
	for (int i = 0; i < BF.MemLen; i++)
		Res.pMem[i] = BF.pMem[i];
	return Res;
}
bool TBitField::operator== (const TBitField& BF) {
	bool flag = true;
	int min = MemLen > BF.MemLen ? BF.MemLen : MemLen;
	for (int i = 0; i < min; ++i)
		if (pMem[i] != BF.pMem[i]) {
			flag = false;
			break;
		}
	if (MemLen > BF.MemLen) {
		for (int i = BF.MemLen; i < MemLen; ++i)
			if (BF.pMem[i] != 0) {
				flag = false;
				break;
			}
	}
	else
		for (int i = MemLen; i < BF.MemLen; ++i)
			if (BF.pMem[i] != 0) {
				flag = false;
				break;
			}
	return flag;
}
TBitField TBitField::operator| (const TBitField& BF) {
	int len = BitLen > BF.BitLen ? BitLen : BF.BitLen;
	TBitField tmp(len);
	for (int i = 0; i < tmp.MemLen; ++i)
		tmp.pMem[i] = BF.pMem[i];
	int min = MemLen > tmp.MemLen ? tmp.MemLen : MemLen;
	for (int i = 0; i < min; ++i)
		tmp.pMem[i] |= pMem[i];
	return tmp;
}
TBitField TBitField::operator~ (void) {
	int len = BitLen;
	TBitField tmp(len);
	for (int i = 0; i < MemLen; ++i)
		tmp.pMem[i] = ~pMem[i];
	return tmp;
}
istream & operator>>(istream &istr, TBitField &BF)
{
	int i = 0;
	char ch;
	do
	{
		istr.get(ch);
	} while (ch != ' ' && ch != '\n');

	while (1)
	{
		istr.get(ch);
		if (ch == '0')
		{
			BF.ClrBit(i++);
		}
		else
			if (ch == '1')
			{
				BF.SetBit(i++);
			}
			else
				break;
	}
	return istr;
}
ostream& operator<< (ostream& os, const TBitField& BF) {
	 int len = BF.GetLenght();
	for (int i = 0; i < len; ++i) {
		if (!(i % 8))
			os << endl;
		if (BF.GetBit(i))
			os << '1';
		else
			os << '0';
	}
	return os;
}

Помогите, пожалуйста
Forsby вне форума Ответить с цитированием
Старый 24.10.2015, 17:40   #2
Forsby
Новичок
Джуниор
 
Регистрация: 24.10.2015
Сообщений: 2
По умолчанию

main


Код:
#include "stdafx.h" 
#include"TBitField.h"  
#include<iostream>
using namespace std;
int main()
{
	int menu;
	int k = 0;
	int b = 0;
	do
	{
		cout<<" Skolko elementov hotite v 1 pole? : ";
		cin>>k;
	} while (k <= 0);
	TBitField A(k);
	cout<<" vvedite pole : "<<endl;
	cin>>A;
	cout<<" pole #1 : "<<A;
	cout<<endl;
	cout<<endl;
	do
	{
		cout<<" Skolko elementov hotite vo 2 pole? : ";
		cin>>b;
	} while (b <= 0);
	TBitField B(b);
	cout<<" vvedite pole : "<<endl;
	cin>>B;
	cout<<" pole #2 : "<<B;
	cout<<endl;
	cout<<endl;
	cout<<" \n";
	do
	{
		cout<<"1. poluchit bit \n";
		cout<<"2. ustanovka sostoyniy bita\n";
		cout<<"3. operaciy ~ \n";
		cout<<"4. operaciy & \n";
		cout<<"5. operaciy | \n";
		cout<<"6. sravnenie na == \n";
		cout<<endl;
		cout<<"vuberite odin iz punktov : ";
		cin>>menu;
		if (menu == 1)
		{
			int x = 0;
			int y = 0;

			cout<<"vvedite nomer poly : ";
			cin>>x;
			cout<<endl;
			cout<<"kakoy bit hotite proverit : ";
			cin>>y;
			cout<<endl;
			if (x == 1)
			{
				cout<<"index : "<<y<<" "<<A.GetBit(y)<<endl;
			}
			else if (x == 2)
			{
				cout<<"index : "<<y<<" "<<B.GetBit(y)<<endl;
			}
		}
		if (menu == 3)
		{
			int x = 0;
			TBitField X(k);
			TBitField Y(b);
			cout<<"vvedite nomer poly : ";
			cin>>x;
			if (x == 1)
			{
				X = A;
				cout<<~X;
			}
			if (x == 2)
			{
				Y = B;
				cout<<~Y;
			}
			cout<<endl;
		}
		if (menu == 4)
		{
			int x = 0;
			if (k>b)
			{
				x = k;
			}
			else (x = b);
			TBitField X(x);
			X = A & B;
			cout<<"A&B = "<<X<<"\n";
		}
	} while (menu != 7);
	return 0;
}
Forsby вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Найти седловые точки в матрице(помогите найти ошибку) - pascal tdsotm Помощь студентам 0 20.11.2014 18:57
Помогите найти ошибку - StrToFloat выдаёт ошибку EConvertError для ячеек StringGrid (Delphi) Artsiom Помощь студентам 10 18.12.2013 14:10
Помогите найти ошибку на С nicheel Помощь студентам 4 07.12.2013 00:05
Помогите найти ошибку Дима82 Помощь студентам 4 19.05.2008 15:05