试图编译以下代码我得到这个编译错误,我该怎么办?
ISO C++禁止获取非限定或带括号的非静态成员函数的地址,以形成指向成员函数的指针.
class MyClass {
int * arr;
// other member variables
MyClass() { arr = new int[someSize]; }
doCompare( const int & i1, const int & i2 ) { // use some member variables }
doSort() { std::sort(arr,arr+someSize, &doCompare); }
};
Run Code Online (Sandbox Code Playgroud) ①在下面的C#代码中,出现了CS1729,但据我所知,CS0122更合适.
namespace A
{
class Program
{
static void Main()
{
Test test = new Test(1);
}
}
class Test
{
Test(int i) { }
}
}
Run Code Online (Sandbox Code Playgroud)
CS1729:'A.Test'不包含带有1个参数的构造函数
CS0122:'A.Test.Test(int)由于其保护级别而无法访问'
②在下面的C#代码中,出现CS0122,但据我所知CS1729更合适
namespace A
{
class Program
{
static void Main()
{
Test test = new Test();
}
}
class Test
{
Test(int i) { }
}
}
Run Code Online (Sandbox Code Playgroud)
CS0122:'A.Test.Test(int)由于其保护级别而无法访问'
CS1729:'A.Test'不包含带0参数的构造函数
问题:①和②中交换CS0122和CS1729是否有任何原因或者是这个C#编译器错误?
PS:可以使用Microsoft Visual C#2010编译器版本4.030319.1重现①和②中的错误.
我正试图在今晚向应用程序商店发布应用程序.我过去几个月一直在开发Xcode 6-Beta 2(仅限Objective-C),并且不知道你不能通过Xcode Beta提交.所以,我在普通Xcode中打开了项目,并在尝试重新存档项目时收到以下错误:
Compilation failed for data model at path '/Users/ME/Library/Developer/Xcode/DerivedData/ProjectDataFolder/Build/Products/Debug-iphoneos/Project.app/Model.momd/Model.mom'
我尝试删除派生数据,清理构建文件夹等标准的东西.我还尝试清理archives文件夹和模拟器应用程序文件夹.都没有奏效.但是,在Xcode Beta中重新打开应用程序是第一次尝试.回到Xcode,发生了同样的错误.
任何帮助都会非常感激.
我在 Xcode 中遇到错误问题。我特意在代码中设置了错误,以便错误显示出来,但它们只出现 5 秒钟,然后就消失了。这使得调试变得极其困难。这是 Xcode 最新版本中的错误吗?
编译器错误CS0283表示只能将基本POD类型(以及字符串,枚举和空引用)声明为const.有没有人有关于这种限制的理由的理论?例如,能够声明其他类型的const值(例如IntPtr)会很好.
我相信这个概念const实际上是C#中的语法糖,它只是用文字值替换了名称的任何用法.例如,给定以下声明,在编译时对Foo的任何引用都将替换为"foo".
const string Foo = "foo";
Run Code Online (Sandbox Code Playgroud)
这将排除任何可变类型,因此他们可能选择此限制而不必在编译时确定给定类型是否可变?
我在初始化常量字符串的常量数组时遇到问题.
从week.h(仅显示相关部分):
class Week {
private:
static const char *const *days = { "mon", "tue", "wed", "thur",
"fri", "sat", "sun" };
};
Run Code Online (Sandbox Code Playgroud)
当我编译时,我得到错误"标量初始化器中的多余元素".我试着把它变成const char**,认为我弄乱了第二个const位置,但是我得到了同样的错误.我究竟做错了什么?
我喜欢在这里使用这个方法:
org.apache.commons.lang.ObjectUtils.equals(Object object1, Object object2)
Run Code Online (Sandbox Code Playgroud)
唯一的缺点(例如,与Google Guava相比),我无法静态导入该方法.即这没用:
import static org.apache.commons.lang.ObjectUtils.equals;
Run Code Online (Sandbox Code Playgroud)
...因为我的Eclipse编译器在编写时无法正确链接该方法
equals(obj1, obj2);
Run Code Online (Sandbox Code Playgroud)
错误是:
Object类型中的方法equals(Object)不适用于参数(...,...)
这是为什么?如果在任何超类型中存在具有相同名称(但不是相同的签名)的方法,我的静态导入方法是否不适用?这是在JLS中正式指定的吗?还是一些Eclipse编译问题?
UPDATE
这也不起作用:
import static org.apache.commons.lang.ObjectUtils.defaultIfNull;
public class Test {
void test() {
defaultIfNull(null, null);
// ^^ compilation error here
}
void defaultIfNull() {
}
}
Run Code Online (Sandbox Code Playgroud)
javac错误消息:
Test.java:5: defaultIfNull() in Test cannot be applied to (<nulltype>,<nulltype>)
defaultIfNull(null, null);
^
1 error
Run Code Online (Sandbox Code Playgroud) 使用以下代码:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> ivec;
for(vector<int>::size_type ix = 0; ix != 10; ix++)
{
ivec.push_back(ix);
}
vector<int>::iterator mid = (ivec.begin() + ivec.end()) / 2;
cout << *mid << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我用g ++编译错误:
iterator_io.cpp: In function `int main()':
iterator_io.cpp:13: error: no match for 'operator+' in '(&ivec)->std::vector<_Tp, _Alloc>::begin [with _Tp = int, _Alloc = std::allocator<int>]() + (&ivec)->std::vector<_Tp, _Alloc>::end [with _Tp = int, _Alloc = std::allocator<int>]()'
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../include/c++/3.4.5/bits/stl_iterator.h:654: note: candidates are: __gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+(const typename …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
public static void main(String[] args) {
try {
String[] studentnames = {
/* this is an array of 9000 strings... */
};
}
}
Run Code Online (Sandbox Code Playgroud)
尝试编译时出现以下错误:
The code of method main(String[]) is exceeding the 65535 bytes limit
Run Code Online (Sandbox Code Playgroud) 鉴于代码:
#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s("ABCDEFGHIJKL");
transform(s.begin(),s.end(),s.begin(),tolower);
cout<<s<<endl;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
呼叫没有匹配功能
transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded function type>)
什么是"未解决重载函数类型"是什么意思?
如果我用tolower我写的函数替换它,它不再是错误.