我想在Ubuntu 9.04上使用gcc 4.3.3来使用unsigned int32.
但是,当我宣布这个时:
unsigned int32 dev_number;
Run Code Online (Sandbox Code Playgroud)
我收到编译错误:
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dev_number’
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我想在这样的集合中插入一个向量:
set<vector<prmEdge> > cammini;
vector<prmEdge> vecEdge;
cammini.insert(vecEdge);
Run Code Online (Sandbox Code Playgroud)
我有这样的编译错误:
prmPlanner.cpp:1285: instantiated from here
/usr/include/c++/4.2/bits/stl_algobase.h:853: error: no match for ‘operator<’ in ‘__first1.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]() < __first2.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]()’
/usr/include/c++/4.2/bits/stl_algobase.h:855: error: no match for ‘operator<’ in ‘__first2.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]() < __first1.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]()’
make[1]: *** [prmPlanner.o] Errore …Run Code Online (Sandbox Code Playgroud) 我有一个类的声明
template<int a, int b>
class C {
public:
array[a][b];
}
Run Code Online (Sandbox Code Playgroud)
我想在这样的函数中使用它作为参数:
bool DoSomeTests(C &c1, C &c2);
Run Code Online (Sandbox Code Playgroud)
但是当我编译时,它告诉我'使用类模板需要模板参数列表.' 我试过了
template<int a, int b>
bool DoSomeTests(C &c1, C &c2);
Run Code Online (Sandbox Code Playgroud)
但我得到了同样的错误.我怎样才能解决这个问题?
我对之前的帖子有一些很好的见解,但是我不知道这些编译错误意味着我可以使用一些助手.模板,朋友和重载都是新的,所以三合一给我一些问题......
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Point<double>::Point<double>(double,double)" (??0?$Point@N@@QAE@NN@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Point<int>::Point<int>(int,int)" (??0?$Point@H@@QAE@HH@Z) referenced in function _main
1>C3_HW8.exe : fatal error LNK1120: 3 unresolved externals
Run Code Online (Sandbox Code Playgroud)
Point.h
#ifndef POINT_H
#define POINT_H
#include <iostream>
template <class T>
class Point
{
public:
Point();
Point(T xCoordinate, T yCoordinate);
template <class G>
friend std::ostream &operator<<(std::ostream &out, const Point<G> &aPoint);
private:
T xCoordinate;
T yCoordinate;
};
#endif
Run Code Online (Sandbox Code Playgroud)
Point.cpp
#include "Point.h"
template <class …Run Code Online (Sandbox Code Playgroud) void trim(string &str)
{
string::iterator it = str.begin();
string::iterator end = str.end() - 1;
// trim at the starting
for(; it != str.end() && isspace(*it); it++)
;
str.replace(str.begin(), it, "");
// trim at the end
for(; end >= str.begin() && isspace(*end); end--)
;
str.replace(str.end(), end, ""); // i get the out_of_range exception here
}
Run Code Online (Sandbox Code Playgroud)
我想修剪一串空格.首先我从起点开始行程并且它工作正常,然后我从末尾找到空格的位置并尝试将其删除并抛出异常.
为什么?
如何插入结构内分配的向量?代码是我写的
struct state{
int time_taken;
vector<int>time_live(1);
string loc_name;
vector<string>loc(1);
};
state A[100];
A[flag1]->loc.insert(flag2);
A[flag1]->time_live.insert(time);
A[flag2]->loc.insert(flag1);
A[flag2]->loc.insert(time);
Run Code Online (Sandbox Code Playgroud)
我得到的错误就是这个
kris_UCS.cpp:11: error: expected identifier before numeric constant
kris_UCS.cpp:11: error: expected ‘,’ or ‘...’ before numeric constant
kris_UCS.cpp:13: error: expected identifier before numeric constant
kris_UCS.cpp:13: error: expected ‘,’ or ‘...’ before numeric constant
kris_UCS.cpp: In function ‘int main()’:
kris_UCS.cpp:60: error: base operand of ‘->’ has non-pointer type ‘state’
kris_UCS.cpp:61: error: base operand of ‘->’ has non-pointer type ‘state’
kris_UCS.cpp:63: error: base operand of ‘->’ …Run Code Online (Sandbox Code Playgroud) 任何人都可以建议为什么这不编译?我想我错过了一些重要的东西.编译器是g ++ 4.2.1(在OS X上),错误是"预期的`;" 在'it'之前,在声明迭代器的行上.
#include <vector>
template <class T>
class A {
public:
struct SomeStruct {
T* ptr;
int i;
};
typedef std::vector<SomeStruct> MyList;
void Func()
{
MyList::iterator it;
}
};
Run Code Online (Sandbox Code Playgroud) 我现在有一个非常庞大的字符串.我需要将它转换为C字符串(char*),因为我想要使用的函数只在参数中使用C字符串.
我的问题在于,我尝试的任何东西都使得最终的C字符串比原始字符串小,因为我的字符串包含许多\ 0.那些\ 0是必不可少的,所以我不能简单地删除它们:( ...
我尝试了各种方法,但最常见的是:
myString.c_str();
myString.data();
Run Code Online (Sandbox Code Playgroud)
不幸的是,C-string始终只是第一个\ 0之前的原始字符串的内容.
任何帮助将不胜感激!
这样安全吗:
int main()
{
boost::int16_t t1 = 50000; // overflow here.
boost::uint16_t t2 = (boost::uint16_t)t1;
std::cout << t1 << " " << t2 << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
更具体一点:我将这些数据存储在一个表中,该表在模式中使用了签名类型,是否可以安全存储,并以这种方式检索这些数据?
谢谢!
考虑一下:
#ifndef GUARD_H
#define GUARD_H
...
#endif GUARD_H
Run Code Online (Sandbox Code Playgroud)
而不是:
#ifndef GUARD_H
#define GUARD_H
...
#endif // GUARD_H
Run Code Online (Sandbox Code Playgroud)
我常常看到#endif一个"标识符"已注释掉,但没有评论它仍然有效.
一切都是在#endif悔改之后还是......?