我试图教一些学生,在下面的例子中你应该通过引用传递,否则将复制对象.
注意:他们还不知道复制构造函数,所以如果可能的话我不想在示例中提到它们.
int sumOfSizes(CObject const & a, CObject const & b)
{
return a.getSize() + b.getSize();
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我一个真实世界的例子,其中总和实际上不是预期的?
我正在开发一个类似于地址簿的项目.首先,我们在一个文本文件中有许多学生.我将实现一个多链表,该列表有2个头+尾指针(头部+尾部指针,用于名称,姓氏).这些指针显示相同的列表但位置不同,因为我按升序添加节点并使用双指针向后打印列表.问题是我通过名称和姓氏添加节点来实现列表,当我插入另一个时,操作成功.但我意识到,当我用她/他的"名字"删除节点并再次打印列表时,学生不存在,但当我按"姓氏"打印列表时,学生确实存在.然后我认识到我实施了两个单独的链表.我被告知只实现一个添加和删除功能.但是,我如何通过其名字指针和姓氏指针一起添加节点?我希望我可以理解地解释我的问题.这是我的代码块.
我的结构:
typedef struct node {
int birth_date;
int zipcode;
int phone_num;
char first_name[50];
char last_name[50];
char city[50];
char address[50];
char email_addr[50];
struct node* fn_next;
struct node* fn_pre;
struct node* ln_next;
struct node* ln_pre;
struct node* birdat_next;
struct node* birdat_pre;
} NODE;
typedef struct {
int fn_count;
int ln_count;
NODE* fn_head;
NODE* ln_head;
NODE* fn_tail;
NODE* ln_tail;
}LIST;
Run Code Online (Sandbox Code Playgroud)
代码块,我逐行读取文件并调用add函数:
while ( !feof(myfile) ) {
NODE* pnew_stu;
if( !(pnew_stu = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
fscanf(myfile,"%s", …Run Code Online (Sandbox Code Playgroud) 我们看起来像这样:
<caching>
<profiles>
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
</profiles>
</caching>
Run Code Online (Sandbox Code Playgroud)
我想知道因为我们的生产网站没有这个节点,但我们的本地开发web.config确实如此.
((ImageView) v.findViewById(R.id.imageViewHeart1)).setImageResource(R.drawable.heart);
Run Code Online (Sandbox Code Playgroud)
我想从我的图片资源中删除我的图片,所以:
((ImageView) v.findViewById(R.id.imageViewHeart1)).setImageResource(null);
Run Code Online (Sandbox Code Playgroud)
什么的,我怎么能这样做?
我有一个PreferenceActivitywhere 3ListPreferences存在。
每个ListPreference都有一些条目(2 或 3)。
我只想突出显示 1 个条目,其余条目在ListPreference.
PreferenceActivity如果我将 ListPreference 更改为 some ,我需要做哪些更改CustomeListPreference?
我从哪里开始?有人可以帮我弄清楚该怎么做吗?
我有这种方法来验证电子邮件地址:
public static bool isEmail(string inputEmail)
{
inputEmail = NulltoString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
Run Code Online (Sandbox Code Playgroud)
但我得到错误:The name 'NulltoString' does not exist in the current context.
有一种string方法相当于NulltoString()?
这是一个面试问题.我不知道如何解决它.任何人都可以帮助我:?
给定结构中成员a的指针,编写一个返回指向结构的指针的例程.
谢谢!
我有一个非常奇怪的问题.
这是我的简化代码,用于解释:
class Bitmap1
{
public Bitmap nImage;
public IntPtr data;
public Bitmap1()
{
int w = 2450;
int h = 2450;
this.data = Marshal.AllocHGlobal(w*h);
nImage = new Bitmap(w, h, w, PixelFormat.Format8bppIndexed, data);
}
}
Run Code Online (Sandbox Code Playgroud)
当w和h等于2448时,如果我调用构造函数,一切都运行良好.
但是当h和w等于2450时,我ArgumentException看起来似乎是由"新的Bitmap(...)"启动的.
我无法理解,文档并没有说有限的尺寸Marshal.AllocHGlobal.
怎么了?还有其他方法可以做我想要的吗?
非常感谢你.
目前,对单元测试生产代码存在挑战。我们具有从传入的WCF消息中检索IP地址的功能。
public void DoSomething(){
var ipAddressFromMessage = GetIpFromWcfMessage();
var IpAddress = IPAddress.Parse(ipAddressFromMessage);
if(IpAddress.IsLoopback)
{
// do something
}
else
{
// do something else
}
}
private string GetIpFromWcfMessage()
{
OperationContext context = OperationContext.Current;
string ip = ...//use the IP from context.IncomingMessageProperties to extract the ip
return ip;
}
Run Code Online (Sandbox Code Playgroud)
问题是,我应该怎么做才能测试IP中的IP检查DoSomething()?
[Test]
Public void DoSomethingTest()
{
//Arrange...
// Mock OperationContext so that we can manipulate the ip address in the message
// Assert.
...
}
Run Code Online (Sandbox Code Playgroud)
是否应该以一种可以模拟它的方式(例如,实现一个接口并模拟该接口的实现)来更改使用Operation上下文的方式?
当我调用此服务时,收到此错误消息:
ContractDescription没有任何操作; 合同必须至少有一项操作
因为我的界面函数[OperationContract()]定义了属性,所以没有任何意义.
界面:
[ServiceContract()]
public interface ITest
{
[OperationContract()]
bool Connect(string password);
}
Run Code Online (Sandbox Code Playgroud)
SVC:
<%@ ServiceHost Language="CS" Debug="true" Service="TestService.Test" CodeBehind="Test.svc.cs" %>
Run Code Online (Sandbox Code Playgroud)
svc.cs:
public class Test : ITest
{
public bool Connect(string password)
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
调用: 配置是以编程方式定义的,因为它是一个库
public sealed class Validator
{
public static bool Connect(string password)
{
return ObtenirCLient().Connect(password);
}
private static LicensingService.LLMrqLicensingClient ObtenirCLient()
{
dynamic endpoint = new EndpointAddress("http://localhost/TestService/Test.svc");
LicensingService.LLMrqLicensingClient client = new LicensingService.LLMrqLicensingClient(ObtenirBinding(), endpoint);
client.Endpoint.Name = "LicHttp";
client.Endpoint.Contract = new Description.ContractDescription("TestService.ITest"); …Run Code Online (Sandbox Code Playgroud) c# ×4
android ×2
c ×2
wcf ×2
asp.net ×1
asp.net-3.5 ×1
bitmap ×1
c++ ×1
caching ×1
exception ×1
linked-list ×1
mocking ×1
reference ×1
rhino-mocks ×1
unit-testing ×1
web-config ×1