Geschrieben von Windows am 08.08.2016 um 21:35:
code: |
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:
|
#include "CTitle.h"
#include <string>
using namespace std;
CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
if(m_contentSize < 0 || m_contentSize > 0){
m_contentSize = contentSize;
}
else{
m_contentSize = 0;
}
if(m_duration <= 0 || m_duration >= 0){
m_duration = duration;
}
else{
m_duration = 0;
}
m_name = name;
m_performer = performer;
if( m_bitRate>=32000 && m_bitRate<= 320000){
m_bitRate = bitRate;
}
else{
m_bitRate = 0;
m_duration = 0;
m_contentSize = 0;
}
}
CTitle::string CTitle::getName() const
{
return m_name;
}
string CTitle::getPerformer() const
{
return m_performer;
}
int CTitle::getDuration() const
{
return m_duration;
}
ostream& operator<< (ostream& lop, CTitle& rop){
lop<< &rop << " " << rop.getName();
lop<< "; " << rop.getPerformer();
lop<< " ; " << rop.getDuration();
lop << " s"; //Ausgabe um s erweitert
}
|
|
Warum werden aber so viele Fehler angezeigt?
Und wie kann ich auf das contentSize bei der Ausgabe zugreifen?
Description Resource Path Location Type
'string' in 'class CTitle' does not name a type CTitle.cpp /CTitle line 50 C/C++ Problem
Member declaration not found CTitle.cpp /CTitle line 50 Semantic Error
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const char [3]') CTitle.cpp /CTitle line 68 C/C++ Problem
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const char [3]') CTitle.cpp /CTitle line 70 C/C++ Problem
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const char [4]') CTitle.cpp /CTitle line 69 C/C++ Problem
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'CTitle*') CTitle.cpp /CTitle line 67 C/C++ Problem
Type 'CTitle::string' could not be resolved CTitle.cpp /CTitle line 50 Semantic Error
control reaches end of non-void function [-Wreturn-type] CEvent.cpp /CEvent line 80 C/C++ Problem
Member 'm_bookedSeats' was not initialized in this constructor CEvent.cpp /CEvent line 12 Code Analysis Problem
Member 'm_curEvents' was not initialized in this constructor CEventDB.cpp /CEvent line 14 Code Analysis Problem
no return statement in function returning non-void [-Wreturn-type] CTitle.cpp /CTitle line 72 C/C++ Problem
No return, in function returning non-void CEvent.cpp /CEvent line 53 Code Analysis Problem
No return, in function returning non-void CTitle.cpp /CTitle line 65 Code Analysis Problem
Statement has no effect 'numSeats*m_pricePerTicket' CEvent.cpp /CEvent line 98 Code Analysis Problem
statement has no effect [-Wunused-value] CEvent.cpp /CEvent line 98 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 55 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 60 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 65 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 70 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 75 C/C++ Problem
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'const char [3]' CTitle.cpp /CTitle line 68 C/C++ Problem
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'const char [3]' CTitle.cpp /CTitle line 70 C/C++ Problem
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'const char [4]' CTitle.cpp /CTitle line 69 C/C++ Problem
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'CTitle*' CTitle.cpp /CTitle line 67 C/C++ Problem
no known conversion for argument 2 from 'const char [3]' to 'CTitle&' CTitle.cpp /CTitle line 65 C/C++ Problem
no known conversion for argument 2 from 'const char [4]' to 'CTitle&' CTitle.cpp /CTitle line 65 C/C++ Problem
no known conversion for argument 2 from 'CTitle*' to 'CTitle&' CTitle.cpp /CTitle line 65 C/C++ Problem
template argument deduction/substitution failed: CTitle line 2753, external location: c:\program files\git\eclipse\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string
.h C/C++ Problem
candidates are: CTitle.cpp /CTitle line 67 C/C++ Problem
candidates are: CTitle.cpp /CTitle line 68 C/C++ Problem
candidates are: CTitle.cpp /CTitle line 69 C/C++ Problem
candidates are: CTitle.cpp /CTitle line 70 C/C++ Problem
std::ostream& operator<<(std::ostream&, CTitle&) CTitle.cpp /CTitle line 65 C/C++ Problem
template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) CTitle line 2753, external location: c:\program files\git\eclipse\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string
.h C/C++ Problem
Geschrieben von eulerscheZahl am 14.08.2016 um 10:57:
Das hier sieht nicht sinnvoll aus:
code: |
1:
2:
3:
4:
5:
|
if (m_contentSize < 0 || m_contentSize > 0) {
m_contentSize = contentSize;
} else {
m_contentSize = 0;
} |
|
Wenn in
m_contentSize ein anderer Wert als 0 steht, ersetze ihn durch den, der in
contentSize übergeben wird. Sonst setze den Wert auf 0 (er ist in diesem Fall übrigens bereits vorher 0).
Nach der Beschreibung im Header müsste das so aussehen:
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
|
//Die Bitrate muss zwischen 32000 und 320000 bit/s liegen.
if (bitrate >= 32000 && bitrate <= 320000)
{
m_contentSize = contentSize;
m_duration = duration;
m_bitrate = bitrate;
}
else
{
//Falls diese Zusicherung verletzt wird, werden die Attribute
//m_bitRate, m_duration und m_contentSize auf 0 gesetzt.
m_contentSize = 0;
m_duration = 0;
m_bitrate = 0;
} |
|
m_contentSize und m_duration hängen also auch von bitrate ab.
Zu deiner eigentlichen Frage: du musst prüfen, in welchem Intervall die Größe liegt.
code: |
1:
2:
3:
4:
5:
6:
|
if (rop.m_contentSize > 9999 * 1024) // > 9999 KiB
lop << rop.m_contentSize / (1024 * 1024) << " MiB";
else if (rop.m_contentSize > 9999) // > 9999 B
lop << rop.m_contentSize / 1024 << " KiB";
else
lop << rop.m_contentSize << " B" |
|
Problem dabei: du kannst nicht auf m_contentSize zugreifen, da private. Im Header gibt es keinen Getter dafür. Entweder machst du einen rein (falls du das darfst) oder du befreundest den ostream, damit er auf private Member zugreifen kann.